Created
September 4, 2011 20:22
-
-
Save billerickson/1193447 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Template Redirect | |
* Use archive-event.php for all events and 'event-category' taxonomy archives. | |
* Use archive-business.php for all businesses and 'business-category' taxonomy archives. | |
* | |
*/ | |
function be_template_redirect( $template ) { | |
if ( is_tax( 'event-category' ) ) $template = get_query_template( 'archive-event' ); | |
if ( is_tax( 'business-category' ) ) $template = get_query_template( 'archive-business' ); | |
return $template; | |
} | |
add_filter( 'template_include', 'be_template_redirect' ); | |
/** | |
* Only show upcoming events in archive queries | |
* | |
*/ | |
function be_event_query( $query ) { | |
global $wp_query; | |
if ( !is_admin() && $wp_query === $query && ( is_post_type_archive( 'event' ) || is_tax( 'event-category' ) ) ) { | |
$meta_query = array( | |
array( | |
'key' => 'be_events_manager_end_date', | |
'value' => time(), | |
'compare' => '>' | |
) | |
); | |
$query->set( 'orderby', 'meta_value_num' ); | |
$query->set( 'order', 'ASC' ); | |
$query->set( 'meta_query', $meta_query ); | |
} | |
} | |
add_action( 'pre_get_posts', 'be_event_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment