Support

Account

Home Forums Backend Issues (wp-admin) Having trouble adding ACF field to admin columns Reply To: Having trouble adding ACF field to admin columns

  • Hi @brotsky_pixie

    The error I meant was the $column_name variable you used instead of $column and the elseif logic instead of else. If your custom post type is “post_staff”, then you should be able to do it like this:

    function my_page_columns($columns)
    {
        $columns = array(
            'cb'         => '<input type="checkbox" />',
            'title'     => 'Last Name',
            'first'     => 'First Name',
            'date'        =>    'Date',
        );
        return $columns;
    }
    
    function my_custom_columns($column)
    {
        global $post;
        
        if ($column == 'first') {
            echo get_field( "first_name", $post->ID );
        }
        else {
             echo '';
        }
    }
    
    add_action("manage_post_staff_posts_custom_column", "my_custom_columns");
    add_filter("manage_post_staff_posts_columns", "my_page_columns");

    I said it’s related to WordPress because this code:

    echo get_field( "first_name", $post->ID ); should show the correct value. The only issue is how you show it.

    Also, could you please set WP_DEBUG to true to see any error messages on the page? Please take a look at this page to learn how to set it: https://codex.wordpress.org/Debugging_in_WordPress.

    I hope this makes sense 🙂