Support

Account

Home Forums Add-ons Repeater Field Query repeater sub-field date

Solved

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(); ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Query repeater sub-field date’ is closed to new replies.