• Resolved westleymon

    (@westleymon)


    Hi –

    I’ve setup a custom post type for events with custom fields added to it (one specifically being event date).

    I’ve successfully queried the posts and sorted by the event date. My next goal is to exclude posts with an event date of at least yesterday.

    Here is my code for the query:

    <?php
    $upcoming_events = new WP_Query(array('post_type' => 'event',
    		  'posts_per_page' => 4,
    		  'order_by' => 'meta_value',
    		  'meta_key' => '_refactord-datepicker',
    		  'order' => 'ASC'));
    while ( $upcoming_events->have_posts() ) : $upcoming_events->the_post(); ?>

    The event date being called by _refactord-datepicker

    Can someone please point me in the right direction for accomplishing my goal? The reason I’ve setup my custom event type rather than using a plugin is because the events need to have options turned on and off like Bottle Service Sign Up, Guest List, etc.

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter westleymon

    (@westleymon)

    Found the answer to my question on this post.

    Changed my code to a get_posts function which enabled me to use the meta_compare option in the query.

    For anyone who might be wondering, my new code looks like this:

    $postslist = get_posts('post_type=event&numberposts=4&order=ASC&meta_key=event_date&meta_compare=>=&meta_value=' . date("m/d/Y") . '&orderby=meta_value_num');
     foreach ($postslist as $post) :
     setup_postdata($post);
    // post layout
    endforeach;

    Enjoy!

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude posts from wp_query based on meta_value’ is closed to new replies.