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


How to identify pages in relationship field with same name

  • Hello,

    I’m working on a website where the client has multiple pages with the same name (they offer identical services in different locations and the pages are subpages of location pages).

    I have set up a relationship field but when you search for one of these pages the only way to differentiate between them currently is by setting a featured image to be returned. Is there a way to extend the info that comes back beyond just showing the featured image? For example by maybe showing the parent page or ID etc?

    Please see attached screenshot for an example when searching for “Peer Support”.

  • Anybody have any ideas? This is becoming a real problem for me as it means I have to just guess when selecting pages and then check the front end and hope for the best. Even if it could return the page title and the URL that would be immensely helpful.

  • 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:

    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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.