Home Forums General Issues Newbie asking how to output choices from a select field


Newbie asking how to output choices from a select field

  • 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">
                    if( have_rows('repeater') ): 
                        while( have_rows('repeater') ): the_row();
                        $select = get_sub_field_object('select');
                        $value = $select['value'];
                            foreach ($select['category'] as $active => $button) :
                            <li <?php echo ($active === $value) ? 'class="selected"' : '' ?>>
                                <?php echo $button; ?>
                            <?php endforeach; ?>
                    <?php endwhile; 
                endif; ?>

    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!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.