【问题标题】:Adding custom field from Easy Property Listing Wordpress plugin从 Easy Property Listing Wordpress 插件添加自定义字段
【发布时间】:2015-10-21 13:47:40
【问题描述】:

我正在使用 Easy Property 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' );

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

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

【问题讨论】:

    标签: php html wordpress content-management-system


    【解决方案1】:

    我想出了如何去做,并想我会分享答案,以防其他人遇到同样的问题。

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

    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' );
    

    代码取决于您要提取的字段类型。如果您使用不同的字段,例如“数字”或“选择框”,这里有说明。

    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 中实际写入了文本。我发现如果我更改命名字段,我的内容就会消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      相关资源
      最近更新 更多