Title: Does get_posts() support tax_query?
Last modified: August 19, 2016

---

# Does get_posts() support tax_query?

 *  [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/does-get_posts-support-tax_query/)
 * The codex says that get_posts uses all the same arguments as query_posts, so 
   why doesn’t the tax_query work with get_posts?
 *     ```
       $myquery['tax_query'] = array(
       	array(
       		'taxonomy' => 'portfolio-tags',
       		'terms' => array('bacon'),
       		'field' => 'slug',
       	),
       );
       $myposts = get_posts( $myquery );
   
       if ($myposts) :
         echo "bacon here!"
       else:
         echo "no freaking bacon";
       endif;
       ```
   
 * echos out “no freaking bacon” which is obviously not the end result i want, but
   was a quick way to test whether it was pulling any data.
 * but if i change $myposts to
 *     ```
       $myposts = query_posts( $myquery );
       ```
   
 * then i get a result.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Azuaron](https://wordpress.org/support/users/azuaron/)
 * (@azuaron)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/does-get_posts-support-tax_query/#post-1912297)
 * I got mine to work:
 *     ```
       $args = array(	'numberposts'=>-1,
       		'order_by'=>'menu_order',
       		'order'=>'ASC',
       		'post_type'=>'book',
       		'exclude'=>$the_id,
       		'tax_query'=>array(array('taxonomy'=>'series',
       					'field'=>'slug',
       					'terms'=>$slug
       					))
       		);
       $series_posts = get_posts($args);
       ```
   
 * The only difference I can see is that my “terms” isn’t in an array. That really
   shouldn’t make a difference, though, since it’s definitely supposed to work with
   arrays.
 *  Thread Starter [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/does-get_posts-support-tax_query/#post-1912298)
 * thanks! actually the difference is that you’ve defined the post type and the 
   taxonomy i was trying to pull from only applied to a specific post type. apparently
   get_posts() only searches posts by default unless you define another post type.
 *  [Azuaron](https://wordpress.org/support/users/azuaron/)
 * (@azuaron)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/does-get_posts-support-tax_query/#post-1912299)
 * Ah, I didn’t realize you were (also) working with an alternate post type.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Does get_posts() support tax_query?’ is closed to new replies.

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)
 * [tax_query](https://wordpress.org/support/topic-tag/tax_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Azuaron](https://wordpress.org/support/users/azuaron/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/does-get_posts-support-tax_query/#post-1912299)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
