Support

Account

Home Forums General Issues Difficulties to sort a post by DatePicker Reply To: Difficulties to sort a post by DatePicker

  • Hello John !

    I finally find a solution and I post it here if it can help someone :

    <?php $custom_query_args = array('numberposts'  => -1,
      'posts_per_page' => 10,
      'post_type'   => 'post',
      'meta_query' => array(
          array(
              'key' => 'type',
              'value' => 'evenement',
              'compare' => '='
          )
      ),
        'meta_key' => 'start_date',
        'orderby' => 'meta_value',
        'order' => 'ASC',
    );
    
    // Instantiate custom query
    $custom_query = new WP_Query( $custom_query_args );
    
    // Output custom query loop
    if ( $custom_query->have_posts() ) :
        while ( $custom_query->have_posts() ) :
            $custom_query->the_post(); ?>
    
    // Here is your code
    
    //Close
    <?php
        endwhile;
    endif;
    wp_reset_postdata(); ?>

    I use WP_Query and resolve my problem of the double meta_key by using the meta_query to display both my posts who are type “event” and to order event by my “start_date” field.

    Thank you !