Hi there,
I have a repeater loop (if, while) to get the sub_fields. However, i’d like to make an if-statement from an option that’s selected outside the repeater fields.
So it’s something like:
<?php if ( have_rows( 'expertises_all' ) ) : ?>
<?php while ( have_rows( 'expertises_all' ) ) :
the_row(); ?>
<div class="single-expertise">
<img src="<?php the_sub_field( 'icon' ); ?>" alt="">
<?php if ( $title = get_sub_field( 'title' ) ) : ?>
<h3><?php echo $title; ?></h3>
<?php endif; ?>
<?php if ( get_sub_field( 'display' ) == 'view-all' ) : ?>
<?php if ( $description = get_sub_field( 'description' ) ) : ?>
<?php echo $description; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
It regards the “get_sub_field (‘display’ == ‘view-all’ )”, which lives outside the repeater loop.
I thought of querying based on the post ID, but the element could show up more than once on the same page so I guess that would mess up the results?
Any suggestions?
if the field “display” in not in the repeater then use get_field('display')
I don’t think it works because it lives inside another Flexible Content row (should have specified), which also requires get_sub_field – right?
If this is a nested repeater/flex situation, you cannot get fields from the parent repeater/flex field. You have to get these values before the nested loop of you want to use them in the nested loop. Let me know if you understand that or you need an example.
I solved it by creating a CSS class from the value before the loop, then hide/show it based on that class.
Not ideal as it’s unnecessary HTML, but works for this situation.
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.