Home › Forums › ACF PRO › Querying relationship fields › Reply To: Querying relationship fields
James,
It was actually quite easy, since the column is there purely for reference (no need to filter etc.). Perhaps the code is useful for someone else! 🙂
function build_listing_column_head( $columns, $post_type = 'listing' ) {
if( ! is_admin() ) {
return;
}
if( $post_type == get_post_type() ) {
$columns['relation'] = esc_html__( 'Relation', 'lystr' );
}
return $columns;
}
add_action( 'manage_listing_posts_columns', 'build_listing_column_head', 10, 2 );
function build_listing_column_content( $column, $post_id ) {
global $post;
if( ! is_admin() || 'relation' !== $column ) {
return;
}
$relation = get_field( 'relationship', $post->ID, false );
if( ! empty( $relation ) ) {
$id = implode( ',', $relation );
$title = get_the_title( $id );
echo $title;
}
}
Thanks for your help! 🙂
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.