Last active
March 28, 2019 19:59
-
-
Save billerickson/1238281 to your computer and use it in GitHub Desktop.
Customize Event Query using Post Meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customize Event Query using Post Meta | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/customize-the-wordpress-query/ | |
* @param object $query data | |
* | |
*/ | |
function be_event_query( $query ) { | |
if( $query->is_main_query() && !$query->is_feed() && !is_admin() && $query->is_post_type_archive( 'event' ) ) { | |
$meta_query = array( | |
array( | |
'key' => 'be_events_manager_end_date', | |
'value' => time(), | |
'compare' => '>' | |
) | |
); | |
$query->set( 'meta_query', $meta_query ); | |
$query->set( 'orderby', 'meta_value_num' ); | |
$query->set( 'meta_key', 'be_events_manager_start_date' ); | |
$query->set( 'order', 'ASC' ); | |
$query->set( 'posts_per_page', '4' ); | |
} | |
} | |
add_action( 'pre_get_posts', 'be_event_query' ); |
Bill, you've got a double &&
in the if statement, FYI. Twice I copied and pasted and forgot to update that ;-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me stupid...when an end date is set (also for one day events) this is not an issue.