Home › Forums › Add-ons › Repeater Field › 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.
https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
see the section 4. Sub custom field values
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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.