php - Wordpress query based on ACF Datepicker values results in no posts -


so added custom fields post posttype, namely event_startdate , event_enddate. goal show events ongoing (so current date between start , enddate). however, no posts showing current code.

this i've got:

<?php         $today = date('ymd');          $args = array (             'posts_per_page'         => '9',             'order'                  => 'asc',             'orderby'                => 'id',           'meta_query'             => array(               array(                 'key'     => 'event_startdate',                 'compare' => '>=',                 'value'   => $today               ),               array(                 'key'     =>  'event_enddate',                 'compare' =>  '<=',                 'value'   => $today               )           )         );          $query = new wp_query( $args );          if ( $query->have_posts() ) {             while ( $query->have_posts() ) { 

and rest of loop. know loop works, because posts show when meta_query removed. issue be? i've experimented different dateformats (hardcoded), didn't seem fix it. tried other solutions posted online well, none seemed fix issue.

edit: started working on query in meantime, time using event_featured, true/false field. code same mentioned code, except args. doesn't return posts either:

     $args = array (         'post_type'              => 'post',         'posts_per_page'         => '9',         'order'                  => 'asc',         'orderby'                => 'id',       'meta_query'             => array(           array(               'key' => 'event_featured',               'value' => '1',               'compare' => '=='           )       )     ); 

i did not see in code declared post type query. add post type query, see first line after first array. try use this:

    $args = array (         'post_type'              =>'posttype',         'posts_per_page'         => '9',         'order'                  => 'asc',         'orderby'                => 'id',       'meta_query'             => array(           array(             'key'     => 'event_startdate',             'compare' => '>=',             'value'   => $today           ),           array(             'key'     =>  'event_enddate',             'compare' =>  '<=',             'value'   => $today           )       )     );      $query = new wp_query( $args );      if ( $query->have_posts() ) {         while ( $query->have_posts() ) { 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -