在自定义列(wp_list_table)中显示高级自定义字段值 [英] Show advanced custom field value in custom column (wp_list_table)
问题描述
我创建了一个名为 address 的自定义帖子类型,并使用插件高级自定义字段向其中添加了值.我想在wp-list-table的自定义列中显示这些值.
I made a custom post type named address and added values to it with the plugin advanced custom fields. I would like to display those values in a custom column in the wp-list-table.
因此,我设法在名为视图的自定义帖子类型(地址)中添加了一列.使用下面的代码.
So I managed to add a column to the custom post type(address) called views. With the code below.
add_filter('manage_edit-address_columns', 'my_columns');
function my_columns($columns) {
$columns['views'] = 'Views';
return $columns;
}
现在,我想用我制作并称为'reserveer_url_theater_terra'(这是一个url字段)的高级自定义字段中的数据填充此列(视图).绑定到自定义帖子类型地址,但是它只显示一个空列'视图',而没有'reserveer_url_theater_terra'字段中的值.我做错了什么,有人可以指出我正确的方向吗?我应该使用wpdb来获取值吗?还是还有其他我应该做的事情?预先谢谢你.
Now I wanted to fill this column (views) with the data from the advanced custom field wich I made and called 'reserveer_url_theater_terra' (it's a url field) and bound to the custom post type address, but it just shows an empty column 'views' without the values from 'reserveer_url_theater_terra' field . What am I doing wrong, could someone point me in the right direction? Should I be using wpdb to get the values? Or is there somthing else I should do? Thank you in advance.
add_action('manage_posts_custom_column', 'my_show_columns');
function my_show_columns($name) {
global $post;
switch ($name) {
case 'views':
$views = get_post_meta($post->ID, 'reserveer_url_theater_terra', true);
echo $views;
}
}
我尝试按照Zork的建议使用get_field,但仍然无法正常工作.
I tried using get_field as Zork suggested, but I still could not get it to work.
$views = get_field('reserveer_url_theater_terra', $post->ID);
推荐答案
我找到了我的问题的答案,它看起来像我的过滤器,操作和函数的名称不正确.我没有正确(愚蠢)并在需要的地方添加自定义帖子类型(地址).这样做之后,一切都开始正常工作.感谢您的帮助.
I found the answer to my question it looks like my filter, action and functions where not named properly. I did not add the custom post type(address) correctly(stupid) and everywhere needed. After doing so, everything started working fine. Thanks for the help.
add_action("manage_address_posts_custom_column", "address_custom_columns");
add_filter("manage_edit-address_columns", "address_edit_columns");
function address_edit_columns($columns){
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Titel",
"theater" => "Theater",
"plaats" => "Plaats",
"datum" => "Datum",
);
return $columns;
} function address_custom_columns($column){
global $post;
switch ($column) {
case "theater":
the_field('theater', $post->ID );
break;
case "plaats":
the_field('plaatss', $post->ID );
break;
case "datum":
the_field('datum', $post->ID );
break;
}
}
这篇关于在自定义列(wp_list_table)中显示高级自定义字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!