Support

Account

Home Forums Add-ons Repeater Field Is this possible with a repeater field

Solving

Is this possible with a repeater field

  • I have a
    CPT called: ‘courses’
    with a repeater called: ‘course_start_repeater’
    A field called: ‘course_date_start’

    What I want to do is query all my courses with a course date start in the future, return the title, and any dates against that post in a list below the title.

    Now I’ve done this query before on a CPT and got it to work, but once I add a repeater in to the mix all I get back is “sorry we have no posts to show” from my ‘else’ I have also used a repeater a few times and got that working but this combo with a date picker, I just cant get it to work.

    I started with this

        <div class="row">
    
            <?php 
    
                    // Find todays date in Ymd format.
                    $today = date('Ymd');
    
                    // args
                    $args = array(
                        'numberposts'	=> -1,
                        'post_type'		=> 'courses',
                        'meta_key'		=> 'course_start_repeater',
                            'meta_query'	=> array(
                            'relation'		=> 'AND',
                            array(
                                'key'		=> 'course_date_start',
                                    'compare'	=> '>=',
                                    'value'		=> $today,
                            ),
                        )
                    );
    
                    // query
                    $the_query = new WP_Query( $args );
    
                    ?>
                    <?php if( $the_query->have_rows() ): ?>
                        <ul>
                            <?php while( $the_query->have_rows() ) : $the_query->the_row(); $date = get_sub_field('course_date_start'); ?>
                                <li>
                                    <a href="<?php the_permalink(); ?>">
                                        <?php the_title(); ?>
                                    </a>
                                    start date = <?php the_sub_field($date); ?>
                                </li>
                            <?php endwhile; ?>
                        </ul>
    
                        <?php else:  ?>
                            <p><?php _e( 'Sorry, we currently have no courses starting for this repeater.' ); ?></p>
                    <?php endif; ?>
    
                    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>
    
            </div>
            <!-- /.row -->

    Ive done a lot of googling and if it was a single value field im trying to query on I can get it to work but as soons as I use a repeater, nothing returns.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.