Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created October 6, 2016 23:11
Change Travelify home page to include Event Espresso events that have the "home page" taxonomy (espresso_event_categories) term.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_action( 'pre_get_posts', 'my_travelify_alter_home', 10 );
function my_travelify_alter_home( $query ){
// add Event Espresso events to home page
if( $query->is_main_query() && $query->is_home() ) {
if ( isset( $query->query_vars['post_type'] ) && $post_types = (array) $query->query_vars['post_type'] ) {
if ( ! in_array( 'post', $post_types ) ) {
return;
}
} else {
$post_types = array( 'post' );
}
if ( ! in_array( 'espresso_events', $post_types )) {
$post_types[] = 'espresso_events';
$query->set( 'post_type', $post_types );
}
// set taxonomy and category for home page
$tax_args = array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'home-page' ),
),
array(
'taxonomy' => 'espresso_event_categories',
'field' => 'slug',
'terms' => array( 'home-page' ),
),
);
$query->set( 'tax_query', $tax_args );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment