Support

Account

Home Forums Front-end Issues Use post chosen via relationship field as permalink

Solved

Use post chosen via relationship field as permalink

  • When users create a new one of my custom post type (“performances”), they have the option to choose an existing post on the website to associate with that performance (e.g. a post that gives more details about a particular theater performance).
    I would like to make a page template that displays the two most recent “performances” (my custom post type), with the title of each performance (title is one of the custom post type’s fields) linked to the associated post the user indicated (via relationship), rather than link (as it does now) to the custom post page (e.g. mysite.com/performances/aperformance).
    How would I go about doing this? Thank you very much for your help!

  • Hi @calanthis99

    If you already have a link, then I will assume that you already have a loop to show the 2 latest performance posts.

    All you need to do is get the selected post, then load it’s permalink. You can do this like so:

    
    $selected = get_field('relationship_field_name');
    $selected = array_pop($selected);
    $permalink = get_permalink($selected->ID);
    
    

    Thanks
    E

  • This reply has been marked as private.
  • Hi I am trying to do the same and this makes sense but where/how in the loop do you use the variable $permalink to get the permalink of the related content and link to it?

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

The topic ‘Use post chosen via relationship field as permalink’ is closed to new replies.