Support

Account

Home Forums Front-end Issues Filtering posts with by date (Date Picker)

Solved

Filtering posts with by date (Date Picker)

  • Hi everyone,

    I was wondering if it is possible to filter posts by date (which is set in a date picker)?
    Right now I have this, which works but isn’t the most elegant solution:

    $wpb_all_query = new WP_Query(array(
        'post_type'=>'workshops',
        'post_status'=>'publish',
        'posts_per_page'=>-5
        ));
        ?>
    
    <?php if ( $wpb_all_query->have_posts() ) : ?>
    
     <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
    <?php $post_id = get_the_ID();?>
    <?php if ( $wpb_all_query->have_posts() ) : ?>
    //if get_field("workshop_startdate", $post_id) is before today
    /* display post */
    <?php endwhile; ?>
    <?php endif; ?>

    Is there a way of having the filtering done in the query?

  • G’day mate,

    If you already have acf date field setup, you can include the date as part of your wp query.

    See the last example “Query posts based on date” in the Date Picket documentation.

    https://www.advancedcustomfields.com/resources/date-picker/

    Cheers, 😇

  • coolness,

    meta query to the rescue 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Filtering posts with by date (Date Picker)’ is closed to new replies.