Home › Forums › Backend Issues (wp-admin) › Having trouble adding ACF field to admin columns › Reply To: Having trouble adding ACF field to admin columns
I was getting the same error when using the above code. Not sure what the problem is. Here’s what I’m using, which seems to work fine:
add_filter('manage_events_posts_columns' , 'mysite_add_book_columns');
function mysite_add_book_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Title',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'location' => 'Location',
'categories' => 'Categories',
'date' => 'Date',
);
return $columns;
}
add_action( 'manage_events_posts_custom_column', 'mysite_custom_event_columns', 10, 2 );
function mysite_custom_event_columns( $column ) {
global $post;
switch ( $column ) {
case 'start_date':
echo get_field( "event_start_date", $post->ID );
break;
case 'end_date':
echo get_field( "event_end_date", $post->ID );
break;
case 'location':
echo get_field( "location", $post->ID );
break;
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.