I’m trying to add ACF information to a column in the edit screen for a custom post type (Events) via the functions.php file of my theme. The issue is that the info I’m looking to add is from a post_object field and is returning the post ID rather than the title.
Here’s the code I’m using:
function change_columns( $cols ) {
$cols = array(
'cb' => '<input type="checkbox" />',
'event_date' => __( 'Event Date', 'trans' ),
'venue' => __( 'Event', 'trans' ),
'city' => __( 'City', 'trans' ),
'artist' => __( 'Artist', 'trans' ),
);
return $cols;
}
add_filter( "manage_event_posts_columns", "change_columns" );
function custom_columns( $column, $post_id ) {
switch ( $column ) {
case "event_date":
$date = get_field('event_date');
echo date("F j, Y (l)", strtotime($date));
break;
case "venue":
echo get_post_meta( $post_id, 'venue_name', true);
break;
case "city":
echo get_post_meta( $post_id, 'city_&_country', true);
break;
case "artist":
echo get_post_meta( $post_id, 'artist', true);
break;
}
}
add_action( "manage_posts_custom_column", "custom_columns", 10, 2 );
The result can be seen in the attached screenshot. How can I echo the title of the post_object called in the “artist” column instead of its ID?
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.