Showing an ACF field in admin posts dashboard

This code worked perfectly fine:

  function custom_columns( $columns ) {
        $columns = array(
            'cb' => '<input type="checkbox" />',
            'title' => 'Title',
            'featured_image' => 'Image',
            'categories' => 'Categories',
            'amazon_url' => 'Amazon Link',
            'comments' => '<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>',
            'date' => 'Date'
         );
        return $columns;
    }

    add_filter('manage_posts_columns' , 'custom_columns');

    function custom_columns_data( $column, $post_id ) {
        switch ( $column ) {
        case 'featured_image':
            the_post_thumbnail( 'thumbnail' );
            break;
        case 'amazon_url' :
             echo get_field( 'product_url', $post_id );
             break;
        }
    }

    add_action( 'manage_posts_custom_column' , 'custom_columns_data', 10, 2 ); 

I realize that there was a spelling error at

case 'anazon_url' : (I updated it in the question though)

It was case 'anazon_url' :

Even after fixing the typo it didn’t work but then I cleared caches and tried again and it was working!

So I am leaving the code here so if anyone wants to display ACF data in admin columns here you go!

Leave a Comment

tech