Want to get posts published between specific dates in WordPress? WP_Query offers a date_query parameter, allowing you to set a range with before and after.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$args = array( 'post_type' => 'event', 'meta_query' => array( 'relation' => 'AND', 'event_start_date_clause' => array( 'key' => '_event_start_date', 'compare' => 'EXISTS', ), 'event_start_time_clause' => array( 'key' => '_event_start_time', 'compare' => 'EXISTS', ), ), 'orderby' => array( 'event_start_date_clause' => 'ASC', 'event_start_time_clause' => 'ASC', ), ); $query = new WP_Query( $args ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.