Title: Multiple Post Type Queries
Last modified: August 19, 2016

---

# Multiple Post Type Queries

 *  [loushou](https://wordpress.org/support/users/loushou/)
 * (@loushou)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-post-type-queries/)
 * So I have a problem…. obviously, right? So if I were to do something like:
 * `get_posts('post_type[]=post_type_1&post_type[]=post_type_2');`
 * I would receive a list of posts that are either of post type ‘post_type_1’ or
   of ‘post_type_2’. Now if I goto a url like the following:
 * `http://www.my-site.com/index.php?post_type[]=post_type_1&post_type[]=post_type_2&
   name=testing-post`
 * I get a 404 error page.
 * How can I make the later example work? I have been browsing the WP base code (
   like always) and found the following line in _classes.php_ on line 278:
 * `$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];`
 * Most probably don’t know what this line actually means, but in short it converts
   all the query vars (everything after the ? in a url) to strings, even those that
   should be arrays (since the WP_Query object supports arrays). So instead my slightly
   parsed url winds up looking like:
 * `http://www.my-site.com/index.php?post_type=Array&name=testing-post`
 * Then later in _classes.php_ on line 289, we have this:
 *     ```
       // Limit publicly queried post_types to those that are publicly_queryable
           if ( isset( $this->query_vars['post_type']) ) {
             $queryable_post_types =  get_post_types( array('publicly_queryable' => true) );
             if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
               unset( $this->query_vars['post_type'] );
           }
       ```
   
 * which does what it says, eliminates my now _post\_type=Array_ from the query 
   completely because ‘Array’ is not only not a proper post type, but it is not ‘
   publicly_queryable’.
 * So, again I ask, how do I get a url like:
 * `http://www.my-site.com/index.php?post_type[]=post_type_1&post_type[]=post_type_2&
   name=testing-post`
 * to work, assuming I do not know which post type it is?
 * p.s. ~ for the really high-level programmers, it is actually a little more in
   depth than this, but this is the basic idea of the problem, and works exactly
   the same way as the actual problem.

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

 *  Thread Starter [loushou](https://wordpress.org/support/users/loushou/)
 * (@loushou)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-post-type-queries/#post-1585109)
 * Well, unfortunately, I still have not come up with any solutions for this on 
   my own, nor through searching the internet for similar problems. So any expertise
   in this area at all, would be much appreciated.
 *  [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-post-type-queries/#post-1585263)
 * For reference, this seems to be a bug in WordPress:
 * [http://core.trac.wordpress.org/ticket/14330](http://core.trac.wordpress.org/ticket/14330)

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

The topic ‘Multiple Post Type Queries’ is closed to new replies.

## Tags

 * [classes.php](https://wordpress.org/support/topic-tag/classes-php/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [post_type](https://wordpress.org/support/topic-tag/post_type/)
 * [query vars](https://wordpress.org/support/topic-tag/query-vars/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-post-type-queries/#post-1585263)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
