Support

Account

Home Forums Backend Issues (wp-admin) How to identify pages in relationship field with same name Reply To: How to identify pages in relationship field with same name

  • Solution

    I should’ve known there would be a built in solution for this. First time I’ve used a filter on the relationship field results, but this is so, so useful.

    For anyone else who comes across this, here’s a helpful tutorial just to bring it all home: https://philkurth.com.au/tips/customise-the-post-titles-in-acf-relationship-field/

    Here’s how I adapted it to show me a bit more info about the returned results and still make it reasonably legible:

      add_filter( 'acf/fields/relationship/result', function ( $title, WP_Post $post, $field_arr ) {
    
        $posted_at = get_post_time( 'U', false, $post->ID );
        $now = current_time( 'timestamp' );
        $diff = human_time_diff( $posted_at, $now );
        $permalink = get_permalink( $post->ID );
    
        return '<strong>' . $title . '</strong><br>' . $permalink . sprintf( ' (%s ago)', $diff );
      }, 10, 3 );

    This outputs the permalink of each page, along with how long ago it was published. Combined with the small featured image this should be enough to recognise any page.

    Just one more reason to love this plugin.