Support

Account

Home Forums General Issues acf sort by date picker not working

Solving

acf sort by date picker not working

  • <?php
    $args = array(
    ‘post_type’ => ‘post’,
    ‘orderby’ => ‘meta_value_num’,
    ‘meta_key’ => ‘project_date1’, //date picker field name
    ‘value’ => date(‘Ymd’),
    ‘type’ => ‘DATE’,
    ‘order’ => ‘ASC’,
    ‘posts_per_page’ => ’15’,
    ‘cat’ =>’200′ //category ID
    );

    $news = new WP_Query($args);
    ?>

      <?php while ($news->have_posts()) : $news->the_post(); ?>

    • <?php the_field(‘project_date1’); ?></br>
      <?php the_title(); ?>
    • <?php endwhile;

    ?>

  • The reason it’s failing is that you have 'type' => 'DATE'. ACF does not store the value as a proper mySQL date. You need to use this field as either a number field or a text field.

  • This reply has been marked as private.
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘acf sort by date picker not working’ is closed to new replies.