Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add this to your theme's functions.php
- function edit_my_query($query) {
- // Modify category and tag listings to include ai1ec events and all uses of the same term
- // across event and post taxonomies
- // ie live-music or arts whether they are event or post categories
- // also include ai1ec events in blog home and feeds
- if ( ( is_home() || is_feed() || is_category() || is_tag() )
- && empty( $query->query_vars['suppress_filters'] ) ) {
- // The 'suppress_filters' test above keeps your menus from breaking
- $post_type = get_query_var('post_type');
- if($post_type && $post_type[0] != 'post') {
- $post_type = $post_type;
- } else {
- $post_type = array('post','ai1ec_event'); // add custom post types here
- }
- $query->set('post_type',$post_type);
- if (is_category() || is_tag()) {
- // Add custom taxonomies to category and tag pages
- if (is_category()) {
- $taxonomy1 = 'category';
- $taxonomy2 = 'events_categories';
- }
- if (is_tag()){
- $taxonomy1 = 'post_tag';
- $taxonomy2 = 'events_tags';
- }
- $queried_object = $query->get_queried_object();
- $slug = $queried_object->slug;
- $query->set('tax_query', array(
- 'relation' => 'OR',
- array(
- 'taxonomy' => $taxonomy1, 'field' => 'slug', 'terms' => $slug
- ),
- array(
- 'taxonomy' => $taxonomy2, 'field' => 'slug', 'terms' => $slug
- )
- ));
- }
- }
- }
- add_action('pre_get_posts', 'edit_my_query');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement