Home Forums Add-ons Repeater Field Nested repeater field query


Nested repeater field query

  • Hello
    I have a site that is displaying a list of books in categories.
    I am using a repeater field for the categories and within that another repeater field for the list of books -each book has title, summary, image and link.

    The first category is always ‘Current Read’ which has 1 book in it.
    When there is a new current read, I have to delete that book and add it to one of the other categories.
    Ideally I would add a book to a category, if it is the current read there would be a checkbox in the nested repeater which would enable me to display that book before the loop.
    I suspect this isn’t going to be possible.
    Can anyone please help?

    Here is the code at the moment:

     <?php if( have_rows('book_recommendations') ): ?>
    	<div id="bookreclist">
    // loop through rows (parent repeater)
    	while( have_rows('book_recommendations') ): the_row(); ?>
    	<div class="bookreccat">
    	<h2><?php the_sub_field('rec_category_title'); ?></h2>
    /////// Book Recommendations
    	// check for rows (sub repeater)
    	     if( have_rows('book_rec_list') ): ?>
    		<?php // loop through rows (sub repeater)
    		while( have_rows('book_rec_list') ): the_row();?>
    		    <li><a href="<?php the_sub_field('book_rec_link'); ?>" target="_blank"><img src="<?php the_sub_field('book_rec_image'); ?>" alt="<?php the_sub_field('book_rec_title'); ?>" /></a>
                            <h3><a href="<?php the_sub_field('book_rec_link'); ?>" target="_blank"><?php the_sub_field('book_rec_title'); ?></a></h3>
                             <?php the_sub_field('book_rec_summary'); ?>
    		<?php endwhile; ?>
                <?php endif; //if( get_sub_field('book_rec_list') ): ?>
    	</div>	<!-- .booklistcat -->
    <?php endwhile;?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.