Opened 16 months ago
Last modified 16 months ago
#61763 new defect (bug)
get_posts($args) returns "auto-drafts" even when "post_status=>publish"
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Query | Keywords: | reporter-feedback |
| Focuses: | Cc: |
Description
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.
Change History (1)
Note: See
TracTickets for help on using
tickets.
Hi @jobst, thanks for opening this ticket!
I'm unable to reproduce this using your code on a test site.
Can you produce this on a clean install?