Forums

Multiple Post Type Queries (3 posts)

  1. loushou
    Member
    Posted 1 year ago #

    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.

  2. loushou
    Member
    Posted 1 year ago #

    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.

  3. scribu
    Member
    Posted 1 year ago #

    For reference, this seems to be a bug in WordPress:

    http://core.trac.wordpress.org/ticket/14330

Topic Closed

This topic has been closed to new replies.

About this Topic