Home › Forums › Front-end Issues › Help with object values within repeater field › Reply To: Help with object values within repeater field
More than likely this has to do with the wp_reset_postdata();
call. Reset post data resets it to the main query.
I’m guessing that you have a secondary query in the template. This happens when you get more than two nested queries in WP.
There are two methods you can use to fix this
if ($icon):
// hold the current post
$temp_post = $post;
$post = $icon;
setup_postdata($post);
?>
<i class="has-circle bg-brand2">
<svg class="icon-<?php the_field('css'); ?>">
<use xlink:href="<?php echo get_template_directory_uri(); ?>/images/icons/icons.svg#icon-<?php the_field('css'); ?>"></use>
</svg>
</i>
<?php
//wp_reset_postdata(); don't do this
// instead do this
$post = $temp_post;
endif;
OR
if ($icon):
$post = $icon;
// do not do this
// setup_postdata($post);
// instead use values in the $icon object
// see changes to get_field() calls
?>
<i class="has-circle bg-brand2">
<svg class="icon-<?php the_field('css', $icon->ID); ?>">
<use xlink:href="<?php echo get_template_directory_uri(); ?>/images/icons/icons.svg#icon-<?php the_field('css', $icon->ID); ?>"></use>
</svg>
</i>
<?php
// do not do this
//wp_reset_postdata();
endif;
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.