从 Easy 属性 Listing Wordpress 插件中添加自定义字段

Adding custom field from Easy Property Listing Wordpress plugin

我正在使用 Easy 属性 Listings Wordpress 插件 (http://easypropertylistings.com.au/),并且正在设置一些自定义字段。我已经设法让它在 CMS 中工作,以便该字段显示,您可以使用以下内容输入数据:

function listings_callback($meta_fields) {
$custom_field = array(
        'id'        =>   'epl-property-listing-custom-data-id',
        'label'     =>   __('Listing Details', 'epl'),
        'post_type' =>   array('property'),
        'context'   =>   'normal',
        'priority'  =>   'default',
        'groups'    =>   array(
            array(
                'id'        =>   'property_listing_lot_width',
                'columns'   =>   '1',
                'label'     =>   'Lot Width',
                'fields'    =>   array(
                    array(
                        'name'      =>   'property_listing_lot_width',
                        'label'     =>   __('Lot Width', 'epl'),
                        'type'      =>   'text',
                        'maxlength' =>   '150'
                    )
                )
            )
        )
    );
$meta_fields[] = $custom_field;
return $meta_fields;
}
add_filter( 'epl_listing_meta_boxes' , 'listings_callback' );

现在我想在我的模板前端添加自定义字段,但我不知道如何调用它。

任何帮助将不胜感激,因为我已经查看了他们所有的文档,但似乎找不到任何有用的东西。

我想出了解决办法,我想我会分享答案,以防其他人遇到同样的问题。

在上面的代码之后,我需要以下内容:

function my_custom_text_field_callback() {
global $property;

$custom_text_field = $property->get_property_meta('property_listing_lot_width');
if ( isset($custom_text_field) ) {
    echo $custom_text_field;
}
}
// Add after the_content of the listing
add_action( 'epl_property_content_after' , 'my_custom_text_field_callback' );

代码取决于您拉取的字段类型。如果您使用不同的字段,例如 'numbers' 或 'select boxes'.

,这里有说明

http://easypropertylistings.com.au/docs/epl_listing_meta_boxes-filter-all-available-meta-fields/

然后在 functions.php 中设置后,您需要将以下内容添加到模板文件中以调用该字段:

<?php do_action('epl_property_content_after'); ?>

我想这是我在尝试调用 'my_custom_text_field_callback' 而不是 'epl_property_content_after.

时感到困惑的地方

另外不要忘记检查您是否在 CMS 中实际写入了文本。我发现如果我对命名字段进行更改,我的内容就会消失。