Make WordPress Core

Opened 12 months ago

Last modified 12 months ago

#60395 new defect (bug)

Filtering posts by open ping_status returns posts with closed ping_status

Reported by: jamieburchell's profile jamieburchell Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

CLI command wp post --ping_status=open returns published sticky posts with a ping_status of closed.

wp post list --ping_status=open --fields=ID,post_status,post_type,ping_status
+------+-------------+-----------+-------------+
| ID   | post_status | post_type | ping_status |
+------+-------------+-----------+-------------+
| 2521 | publish     | post      | closed      |
| 2508 | publish     | post      | closed      |
+------+-------------+-----------+-------------+

The same command with a different output format yields no results:

wp post list --ping_status=open --format=ids
(no output)

Setting an arbitrary ping_status still returns results;

wp post list --ping_status=foobar --fields=ID,post_status,post_type,ping_status
+------+-------------+-----------+-------------+
| ID   | post_status | post_type | ping_status |
+------+-------------+-----------+-------------+
| 2521 | publish     | post      | closed      |
| 2508 | publish     | post      | closed      |
+------+-------------+-----------+-------------+

The command should return no results as there are no posts with ping_status of open. At the very least, the results output should be consistent regardless of format.

Environment

OS:     Linux 4.18.0-513.9.1.el8_9.x86_64 #1 SMP Wed Nov 29 18:55:19 UTC 2023 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php
PHP version:    8.1.27
php.ini used:   /etc/php.ini
MySQL binary:   /bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.5.22-MariaDB, for Linux (x86_64) using  EditLine wrapper
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /var/www
WP-CLI packages dir:
WP-CLI cache dir:       /home/deploy/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:  /var/www/wp-cli.yml
WP-CLI version: 2.9.0

GitHub issue:

https://github.com/wp-cli/entity-command/issues/453

Change History (1)

#1 @danielbachhuber
12 months ago

  • Component changed from Posts, Post Types to Query
  • Version 6.4.2 deleted

To clarify, the offending line of code is here:

https://github.com/WordPress/wordpress-develop/blob/c45f527fbd8ec82366847eb934620b85991f8af3/src/wp-includes/class-wp-query.php#L3221-L3242

When 'fields' => 'ids' is provided, sticky posts are ignored.

I don't know that it makes sense to change this behavior, but we can at least have it documented in a Trac ticket.

Note: See TracTickets for help on using tickets.