[wp-trac] [WordPress Trac] #16949: Custom post types: error on page if query contains multiple post types

WordPress Trac wp-trac at lists.automattic.com
Wed Mar 23 17:19:22 UTC 2011


#16949: Custom post types: error on page if query contains multiple post types
--------------------------+-----------------------------
 Reporter:  mastermind    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 I'm using custom post types, and I modified the $query to include multiple
 post types. This works quite well, until I enter a URL to a non-existant
 post (modifying the last part, i.e. the post's slug).

 {{{

 // some HOWTO linked from the Codex suggests this,
 // can't find the link right now

 function add_posttypes_to_query($query)
 {
         if (!is_admin() && !$query->query_vars['suppress_filters'])
         {
                 if (!is_home())
                         $post_type = array('video', 'post');

                 $query->set('post_type', $post_type);
         }

         return $query;
 }

 add_filter('pre_get_posts', 'add_posttypes_to_query');
 }}}

 The error I get is: “Warning: Illegal offset type in isset or empty in
 /home/lxg/www/shops.supreme.de/supremeshops/branches/private_wp3/wp-
 includes/post.php on line 811”.

 It appears that the function {{{get_post_type_object}}} gets the array
 passed if no posts were found.

 Also, I realized that custom post single pages don't issue a HTTP 404
 status on errors. But this may be due to local modifications. I am
 currently not able to set up an environment where I isolate this problem.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16949>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list