[wp-trac] [WordPress Trac] #18475: get_post_type_object is sometimes passed an array

WordPress Trac wp-trac at lists.automattic.com
Thu Aug 18 17:29:41 UTC 2011


#18475: get_post_type_object is sometimes passed an array
--------------------------+-----------------------------
 Reporter:  t31os_        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Post Types    |    Version:  3.2.1
 Severity:  minor         |   Keywords:  needs-patch
--------------------------+-----------------------------
 The `get_post_type_object` function does not support arrays, yet it seems
 at times the value passed to it will be an array.

 In some cases the `$post_type` global is passed to the function as an
 array, this in turn generates notices because the function is expecting a
 string.

 Typically you'll see something like..

   Warning: Illegal offset type in isset or empty in C:\path\to\install\wp-
 includes\post.php on line 825

 And potentially 2 more additional notices can be generated by
 `wp_count_posts` which is passed the `$post_type` global by `get_views()`.

 File: '''class-wp-posts-list-table.php'''[[BR]]
 Lines: '''129 - 136'''

 {{{
         function get_views() {
                 global $post_type, $post_type_object, $locked_post_status,
 $avail_post_stati;

                 if ( !empty($locked_post_status) )
                         return array();

                 $status_links = array();
                 $num_posts = wp_count_posts( $post_type, 'readable' );
 }}}

 For an easy demostration of an array of values being passed, open
 `edit.php` in your install with `post_format` passed as a query var, eg.
 `wp-admin/edit.php?post_format=aside`.

 I'm not sure why that particular query puts the post type into an array(it
 shows up as an array inside the WP_Query object to). Passing
 `&post=type=post` into the query string does not change the outcome  and
 i'm not sure on what the cause is, the only place i could see any
 `$post_type` variable cast to an array is inside `update_post_caches()`,
 though it's my understanding `WP_Query` does support passing an array of
 post types to the query, so perhaps it's a side-effect of something there.

 Tested without any plugins enabled, and with the theme's functions file
 stripped down(ie. empty).

 '''NOTE:''' Despite the notices, the `post_format` query var does work,
 and return the correct result set.

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


More information about the wp-trac mailing list