[wp-trac] [WordPress Trac] #61763: get_posts($args) returns "auto-drafts" even when "post_status=>publish"
WordPress Trac
noreply at wordpress.org
Fri Jul 26 01:19:18 UTC 2024
#61763: get_posts($args) returns "auto-drafts" even when "post_status=>publish"
-------------------------------------------------+-------------------------
Reporter: jobst | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Query | Version:
Severity: normal | Keywords:
Focuses: accessibility, administration, |
performance |
-------------------------------------------------+-------------------------
Frustrating bug this one is - had this for a while so not related to the
current version.
Wordpress: 6.6.1
PHP: 8.2.21
When I use the following code
{{{
$args = array( 'post_type'=>'post', 'post_status'=>'publish',
'numberposts'=>5 );
error_log("ARGS -> \n".print_r($args,1),3,"/var/log/php");
$posts = get_posts($args);
foreach($posts as $k => $v)
{
error_log("--------------------------------\n",3,"/var/log/php");
error_log("PT ".$v->post_title."\n",3,"/var/log/php");
error_log("PS ".$v->post_status."\n",3,"/var/log/php");
error_log("PY ".$v->post_type."\n",3,"/var/log/php");
}
}}}
It will print out
{{{
ARGS ->
Array
(
[post_type] => post
[post_status] => publish
[numberposts] => 5
)
--------------------------------
PT Auto Draft
PS auto-draft
PY post
--------------------------------
PT Stuck in the Valley of Indecision?
PS draft
PY post
--------------------------------
PT Game Over: How Fair Play Can Rebuild the Construction Industry
PS publish
PY post
--------------------------------
PT The Power of Reflection for Sales Success
PS publish
PY post
--------------------------------
PT Trend 5 - Process AND Agency
PS publish
PY post
}}}
basically **completely ignoring** my request for 5 **published** posts.
Wordpress' manual for get-posts
(https://developer.wordpress.org/reference/functions/get_posts/) clearly
states that the allowed passed parameter for "$args" can be found in
WP_Query::parse_query
(https://developer.wordpress.org/reference/classes/WP_Query/parse_query/)
which "post_status" is one of them.
I consider this a bug as get_query does not listen to my request ONLY to
hand over "published" posts.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61763>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list