Home › Forums › Add-ons › Repeater Field › Query repeater sub-field date
Hello guys !
Before i had a script that worked perfectly and query posts with a date that was between now and 1 year after just here ! My date field was not in a repeater field !
<?php
date_default_timezone_set('Europe/Paris');
$date_1 = date('Ymd', strtotime("now"));
$date_2 = date('Ymd', strtotime("+12 months"));
?>
<?php
$upcoming_args = array(
'category_name' => '2017',
'post_type' => 'shows',
'posts_per_page' => 100,
'meta_key' => 'end_date',
'meta_compare' => 'between',
'meta_type' => 'numeric',
'meta_value' => array($date_1, $date_2),
'orderby' => 'meta_value_num',
'order' => 'ASC');
?>
<?php $upcoming_query = new WP_Query( $upcoming_args ); ?>
<?php if ( $upcoming_query->have_posts() ) : ?>
<?php while ( $upcoming_query->have_posts() ) : $upcoming_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<?php endif; ?>
But now i’ve got my date in a repeater field with other dates, and i don’t know how to make the query work !
Anyone can help me ?
Thanks Ben
I found the answer, if it can help !
<?php
date_default_timezone_set('Europe/Paris');
$date_1 = date('Ymd', strtotime("now"));
$date_2 = date('Ymd', strtotime("+12 months"));
?>
<?php
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'evenement_%", "meta_key LIKE 'evenement_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
?>
<?php
$upcoming_args = array(
'category_name' => '2017',
'post_type' => 'spectacles',
'posts_per_page' => 100,
'meta_key' => 'evenement_%_date_fin_evenement',
'meta_compare' => 'between',
'meta_type' => 'numeric',
'meta_value' => array($date_1, $date_2),
'orderby' => 'meta_value_num',
'order' => 'ASC');
?>
<?php $upcoming_query = new WP_Query( $upcoming_args ); ?>
<?php if ( $upcoming_query->have_posts() ) : ?>
<?php while ( $upcoming_query->have_posts() ) : $upcoming_query->the_post(); ?>
The topic ‘Query repeater sub-field date’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.