Support

Account

Home Forums General Issues Pull Relationship field permalink

Solving

Pull Relationship field permalink

  • Hi there,

    I currently have a relationship field called “film_filmreview” which is related to the “Post” type and has a Return Format of Post ID. I’ve currently got the selected Post ID pulling through correctly but I can’t find a way of getting the permalink from the post – is this even possible? Unfortunately, using “the_permalink” on the ID of the $selected variable just returns the URL of the page you’re on.

    Below is what I have so far, put together from another Relationship-related post I found.

                            <?php
                            $selected = get_field('film_filmreview');
                            $selected = array_pop($selected); ?>
    
                            <?php echo $selected;
                            $permalink = the_permalink($selected->ID); ?>

    Thanks in advance!

  • Sorry, I realised I must have posted that up in haste… here is the complete version with the permalink echo:

                            <?php
                            $selected = get_field('film_filmreview');
                            $selected = array_pop($selected); ?>
    
                            <?php echo $selected;
                            $permalink = the_permalink($selected->ID); ?>
    
                        </div>
                        <h1 style="word-break: break-word;"><?php echo $selected ?>
                            <?php $permalink = the_permalink($selected->ID); ?></h1>
  • the_permalink() cannot be used for the permalink of an arbitrary post, even though it allows you to specify a post ID.

    Also, if it did it would echo the permalink, not return it.

    See get_permalink()

  • The Relationship field provides a double-column component to select one or more posts, pages for custom post type items.

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

You must be logged in to reply to this topic.