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.
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.
1 Answer
Reset to default 1This 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!
amazon
incorrect incase 'anazon..'
so I thought it was the problem, but I just fixed the mistake and its still the same. – Deepak Kamat Commented Sep 4, 2018 at 13:24