Php 从简易属性列表Wordpress插件添加自定义字段

Php 从简易属性列表Wordpress插件添加自定义字段,php,html,wordpress,content-management-system,Php,Html,Wordpress,Content Management System,我正在使用Easy Property Listings Wordpress插件()并设置一些自定义字段。我已设法使其在CMS中工作,以便字段显示,并且您可以使用以下命令输入数据: function listings_callback($meta_fields) { $custom_field = array( 'id' => 'epl-property-listing-custom-data-id', 'label' =>

我正在使用Easy Property Listings Wordpress插件()并设置一些自定义字段。我已设法使其在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' );
现在我试图在模板的前端添加自定义字段,但我不知道如何调用它


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

我想出了解决方法,并认为如果其他人有同样的问题,我会与他们分享答案

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

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' );
代码取决于您正在提取的字段类型。如果您使用的是不同的字段,如“数字”或“选择框”,则此处有相关说明

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

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

我想这就是我困惑的地方,因为我试图调用“我的自定义\文本\字段\回调”而不是“epl \属性\内容\之后”


另外,别忘了检查你有文本实际上写在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' );
代码取决于您正在提取的字段类型。如果您使用的是不同的字段,如“数字”或“选择框”,则此处有相关说明

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

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

我想这就是我困惑的地方,因为我试图调用“我的自定义\文本\字段\回调”而不是“epl \属性\内容\之后”

另外,别忘了检查你有文本实际上写在CMS。我发现,如果我对命名字段进行更改,我的内容就会消失