Showing an ACF field in admin posts dashboard

Question

Looking for a way to display a post’s ACF data in admin columns using manage_posts_columns hook.

In my functions.php I have this:

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 want the ACF field which is product_url for each post appear in the admin dashboard of the post list, the column ‘Amazon Link’ is there however it seems like the data isn’t getting there at all.

0
Deepak Kamat 3 years 2018-09-04T08:21:10-05:00 0 Answers 79 views 0

Leave an answer

Browse
Browse