Advertisement
Guest User

plugin:Events-Manager Exclude Recurring via Custom Taxonomy

a guest
Mar 27th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. //  MOVED THIS QUERY OUTSIDE THE LOOP AND IT WORKED    
  2.                 //      TODO:       GET THIS AS A UNIQUE FUNCITON I CAN CALL
  3.  
  4. // saving the original / existing wordpress query
  5. $temp_query = clone $wp_query;
  6.  
  7. //  What we're doing is looking for featured events that are also recurring events
  8. //  Then excluding those recurring events
  9. //  if you just want to exclude recurring events , you could remove the noted section
  10. $pagesorter = array(
  11.     //  if you wanted to further filter by a specific tag
  12.     //  I don't so its commented out but you may need it
  13.     //'tag' => 'resource',
  14.         'post_type' => 'event',
  15.     'tax_query' => array(
  16.  
  17.     //  START OPTIONAL
  18.     //  If you want recurring events that are ALSO Featured Events
  19.     //      Then just remove the slash star /**/   
  20. /*
  21.             'relation' => 'AND',
  22.         array(
  23.             'taxonomy' => 'event-categories',
  24.             //  you could list more than one term here as follows
  25.             //'terms' => array( 'featured-events', 'comedy' )
  26.             //  I only need the one I want to include
  27.                         'terms' => array( 'featured-events'),
  28.                         'field' => 'slug',
  29.                         'operator' => 'IN'
  30.         ),
  31. */
  32.     //  END OPTIONAL
  33.  
  34.         //  note how tax_query MUST BE a nested array
  35.             //  ie. "array(    array("
  36.         array(
  37.             'taxonomy' => 'event-categories',
  38.             //  you need to have an Event Category with the slug "recurring-events"
  39.             //  then you need to edit your recurring events to add this term
  40.                         'terms' => array( 'recurring-events'),
  41.                         'field' => 'slug',
  42.             'operator' => 'NOT IN'
  43.         )
  44.     ),
  45.         'posts_per_page' => -1,
  46.         'paged' => $paged,
  47. );
  48. //  lets run a new Query
  49. //  to do this you would need this code to be outside the main loop
  50. $customPosts = new WP_Query($pagesorter);
  51.  
  52. $cat_post_ids = array();
  53. // starting loop
  54. while ($customPosts->have_posts()) : $customPosts->the_post();
  55.    
  56.     //  some optional tests to make sure we're returning the correct data
  57.     //$count++;
  58.     //echo 'count'.$count;  //  lets get a count of how many posts get returned
  59.     //    echo '+ + + ID'.get_the_ID().'- - -'; //  lets see the id of each returned post
  60.     //the_title();  //  lets see the title of each returned post
  61.    
  62.     array_push($cat_post_ids, $post->ID);  
  63.  
  64. endwhile;
  65.     //  optional test - lets see if we get the array we wanted.
  66.     //print_r($cat_post_ids);
  67.  
  68.  // restoring the original query so it can be later used to display our posts
  69.  $wp_query = clone $temp_query;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement