Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created September 4, 2011 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/1193447 to your computer and use it in GitHub Desktop.
Save billerickson/1193447 to your computer and use it in GitHub Desktop.
<?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