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;
}
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;
}
}
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;
}
}