Support » Themes and Templates » How to meta_query dates using WP_Query

  • Hi!

    I have made two custom post types, “exhibitions” and “events”.

    For “exhibitions” there are two custom fields (meta_key): startdate and enddate.
    For “events” there is one custom field (meta_key): date.

    I want to use php’s date() and WP_Query to show all “exhibitions” and “events” that are on today. Thus i need to query wether today’s date is within the range of startdate and enddate or on date.

    To find today’s date i use:

    $todaysdate = strtotime(date("Y-m-d"));

    My WP_Query so far:

    $args = array(
    'post_type' => array( 'exhibitions', 'events' ),
    'meta_query' => array(
    'key' => 'wpcf-date',
    'value' => '$todaysdate',
    'compare' => 'LIKE'
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
    echo 'hello';

    How do adjust the meta_query to also show exhibitions where today’s date is between the start- and enddate?


  • The topic ‘How to meta_query dates using WP_Query’ is closed to new replies.