0

by ACF I added custom field called "status" and it is select field. Values are: "Pending", "Active", "Disabled". I found code below to add custom column, and it workds fine but only for textfield, if it is select field instead of value in column there is "Array". How to fix that? Code that Im using

add_filter('manage_posts_columns', 'my_columns');
function my_columns($columns) {
$columns['status'] = 'Status płatności';
return $columns;
}
add_action('manage_posts_custom_column',  'my_show_columns');
function my_show_columns($name) {
global $post;
switch ($name) {
    case 'status':
        $views = get_post_meta($post->ID, 'status', true);
        echo $views;
}}

1 Answer 1

0

You created the field with ACF so we can get the value with ACF too by using the get_field() function. You're saying you get the value as an array so you probably put the return value of the select field in acf as label and value as array. This code shows how to show the label:

add_filter('manage_posts_columns', 'my_columns');
function my_columns($columns) {
$columns['status'] = 'Status płatności';
return $columns;
}
add_action('manage_posts_custom_column',  'my_show_columns');
function my_show_columns($name) {
global $post;
switch ($name) {
    case 'status':
        $views = get_field( 'status', $post->ID )['label'];
        echo $views;
}}

If you want to show the value instead you can use:

get_field( 'status', $post->ID )['value']
4
  • Hi Wilco! Thx for answer. But your solution not working for me... Instead of "Array" now there is nothing, empty field in column..
    – manx
    Jan 9, 2018 at 10:07
  • Try to debug the array with print_r( ${your array} ) to know whats in the array.
    – Wilco
    Jan 9, 2018 at 10:28
  • Ok, where to put this code? I'm kinda noob for now with this stuf..
    – manx
    Jan 9, 2018 at 10:57
  • Here you go
    – Wilco
    Jan 9, 2018 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.