Combining categories (Query posts with multiple taxonomy terms)

I'm attempting to display a list of all posts from multiple categories (if anyone answers this, you might want to include combining tags as well, as probably that will make this answer comprehensive for future seekers).

Here's what I'm working with:

This function works to show a list:

function my_custom_loop_three_posts($category, $tag, $offset) {         $args=array(           // showposts has been replaced, use 'posts_per_page' instead           // 'showposts'        => 1,           'posts_per_page'      => 3,           // this has been replaced, use 'ignore_sticky_posts'           // 'caller_get_posts' => 1,           'ignore_sticky_posts' => true,         );          if ($category) {           $args['cat'] = $category;         }          if ($tag) {           $args['tag'] = $tag;         }          if ($offset) {           $args['offset'] = $offset;         }          $my_query = new WP_Query($args);         // ... rest of function to output loop   if( $my_query->have_posts() ) {             while ($my_query->have_posts()) : $my_query->the_post(); ?>              <div class="">               <a href="<?php the_permalink() ?>" >    <div class="menu-item-list-item menu-item-list-item-not-title">       <?php the_title(); ?>    </div>               </a>              </div>             <?php             endwhile;         } //if ($my_query)          wp_reset_query();  // Restore global post data stomped by the_post().     };   function myFilter($query) {     if ($query->is_feed) {         $query->set('cat','-121');     } return $query; } add_filter('pre_get_posts','myFilter'); 

And I just use this to display the list on a page:

<?php my_custom_loop_three_posts(330, NULL, 1); ?> 

Because this function works fine, I was hoping to be able to modify it to show multiple categories / tags in the results, but am a bit stumped on this. Maybe it's easy, maybe hard? Solutions OR pointing me towards how to fix this welcome. Thanks


Category: wp query Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.171 (s). 12 q(s)