I’ve been hunting for answers on this in the documentation and forums but nothing I try seems to work for me.
I have a group of fields, let’s call it Field Group;
Among the fields is a Select item, let’s call it Category (slug: category);
The Category has three entries, let’s call them Category 1, Category 2, Category 3;
I want to create buttons out of those categories that will display in the front end, ultimately they will determine what is displayed from a custom post type using WP_Query. At the moment my WP_Query just displays all of the posts from that custom post type which is a bit disorganised.
In quite a few of the examples it mentions ‘repeater’ but I have no idea what that is or how it relates to my fields or code.
So, after much mucking about and trying various things this is what I have at the moment, I get nothing output to the front end:
<div class="category-buttons">
<?php
if( have_rows('repeater') ):
while( have_rows('repeater') ): the_row();
$select = get_sub_field_object('select');
$value = $select['value'];
?>
<ul>
<?php
foreach ($select['category'] as $active => $button) :
?>
<li <?php echo ($active === $value) ? 'class="selected"' : '' ?>>
<?php echo $button; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endwhile;
endif; ?>
</div>
I get the feeling I’m missing something really simple, I’m fairly sure ‘repeater’ shouldn’t be in my code but I don’t know what should be there in it’s place. Hope you can help!