Home › Forums › General Issues › 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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.