Support

Account

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! 🙂