I have a repeater field type “Post Object”, returning the Post ID.
Now, on a custom post type page, I want to insert a link to the post selected in the repeater field.
I can’t get it to work. I’m trying the following (and I’ve tried a lot of variations!)
<?php $postid = the_sub_field('post_id') ?>
<a href="<?php echo get_permalink( $postid ); ?>">Link to post</a>
Any suggestions? Thanks!
Use get_sub_field()
instead of the_sub_field()
.
the_sub_field()
echos the value instead of returning it.
<?php $postid = get_sub_field('post_id') ?>
<a href="<?php echo get_permalink( $postid ); ?>">Link to post</a>
Thanks John! That did it.