I’m using Advanced Custom Fields on my website.
I have a repeater field called anime_par, with sub_field called animateur. Sub field animateur is a post-object.
Iâm using this inside a loop in my page, a loop that displays posts from a category inside a custom post type.
What Iâm trying to do is to display the post name and post link of the animateur selection inside my page.
Here is the code Iâm using but itâs not working, it displays the permalink of my current page, not the one selected in the custom field.
<?php while(has_sub_field('anime_par')): ?>
<a href="<?php echo get_permalink('the_sub_field("animateur")'); ?>"><?php echo get_title('the_sub_field("animateur")'); ?></a>
<?php endwhile; ?>
Any suggestions to make this work?
thanks for your help,
This method is working for me, per the repeater and post object docs on ACF. You’ve got to set up the post object inside of the repeater loop.
I added in your field names, and some completely optional html to show the structure.
Hope it helps.
the_sub_field
doesn’t work withouthas_sub_field
What you have to do it is use loop with
has_sub_field
as it said in the documenration http://www.advancedcustomfields.com/resources/functions/the_sub_field/or you can use
get_field('repeater_sluf')
like that