Advertisement
Guest User

Event Calendar Blog and Feed

a guest
Mar 5th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. // Add this to your theme's functions.php
  2. function edit_my_query($query) {
  3. // Modify category and tag listings to include ai1ec events and all uses of the same term
  4. // across event and post taxonomies
  5. // ie live-music or arts whether they are event or post categories
  6. // also include ai1ec events in blog home and feeds
  7. if ( ( is_home() || is_feed() || is_category() || is_tag() )
  8. && empty( $query->query_vars['suppress_filters'] ) ) {
  9. // The 'suppress_filters' test above keeps your menus from breaking
  10. $post_type = get_query_var('post_type');
  11. if($post_type && $post_type[0] != 'post') {
  12. $post_type = $post_type;
  13. } else {
  14. $post_type = array('post','ai1ec_event'); // add custom post types here
  15. }
  16. $query->set('post_type',$post_type);
  17. if (is_category() || is_tag()) {
  18. // Add custom taxonomies to category and tag pages
  19. if (is_category()) {
  20. $taxonomy1 = 'category';
  21. $taxonomy2 = 'events_categories';
  22. }
  23. if (is_tag()){
  24. $taxonomy1 = 'post_tag';
  25. $taxonomy2 = 'events_tags';
  26. }
  27. $queried_object = $query->get_queried_object();
  28. $slug = $queried_object->slug;
  29. $query->set('tax_query', array(
  30. 'relation' => 'OR',
  31. array(
  32. 'taxonomy' => $taxonomy1, 'field' => 'slug', 'terms' => $slug
  33. ),
  34. array(
  35. 'taxonomy' => $taxonomy2, 'field' => 'slug', 'terms' => $slug
  36. )
  37. ));
  38. }
  39. }
  40. }
  41. add_action('pre_get_posts', 'edit_my_query');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement