[wp-trac] [WordPress Trac] #51852: "any" value in "post_type" param in "get_posts" by default ignore attachments
WordPress Trac
noreply at wordpress.org
Mon Nov 23 09:45:48 UTC 2020
#51852: "any" value in "post_type" param in "get_posts" by default ignore
attachments
--------------------------+-----------------------------
Reporter: dam6pl | Owner: (none)
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When creating a simple call to get all posts for all post types by default
to the parameters are adding `post_status` parameter with `publish` value.
{{{#!php
<?php
get_posts(['post_type' => 'any']);
}}}
To the `WP_Query` instance are supplied followed arguments:
{{{#!php
<?php //wp-includes/post.php:2053
[
"numberposts" => 5
"category" => 0
"orderby" => "date"
"order" => "DESC"
"include" => []
"exclude" => []
"meta_key" => ""
"meta_value" => ""
"post_type" => "any"
"suppress_filters" => true
"post_status" => "publish"
"posts_per_page" => 5
"ignore_sticky_posts" => true
"no_found_rows" => true
]
}}}
All attachment posts have `inherit` post status so by default are ignored
in this query.
To actually get all post types the first function parameters should be
expended by `post_status` parameter with `['publish', 'inherit']` value.
{{{#!php
<?php
get_posts(['post_type' => 'any', 'post_status' => ['publish',
'inherit']]);
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51852>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list