WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 3 months ago

#44305 closed defect (bug) (fixed)

The 'fields' query parameter for WP_Query supports only a string

Reported by: ocean90 Owned by: johannadevos
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Query Keywords: good-first-bug has-patch
Focuses: docs Cc:

Description

In the DocBlock of WP_Query::parse_query() the type of $fields is currently documented as string|array but it's only a string as it only accepts 'ids' and 'id=>parent'. Looks like it has been copied from WP_User_Query.

Related: #19866.

Attachments (3)

44305.diff (2.1 KB) - added by palmiak 2 years ago.
44305.2.diff (1.5 KB) - added by johannadevos 20 months ago.
Second patch that fixes whitespace and removes an irrelevant description
44305.3.diff (1.5 KB) - added by ocean90 4 months ago.

Download all attachments as: .zip

Change History (11)

@palmiak
2 years ago

#1 @noisysocks
2 years ago

  • Keywords has-patch added; needs-patch removed

#2 @johannadevos
20 months ago

I have created a second patch which improves the first patch (44305.diff) in two ways:

  • It fixes whitespace: in the first patch, $fields (and the description after it) on line 634 were one space character to the left of all of the other code.
  • I have removed the text "or array of fields" from the $fields description.

@johannadevos
20 months ago

Second patch that fixes whitespace and removes an irrelevant description

#3 @noisysocks
19 months ago

  • Keywords needs-refresh added
  • Owner set to johannadevos
  • Status changed from new to assigned

Thanks for the patch!

Reading the updated comment, it's not 100% clear to me that fields can be set to three and only three options:

  • 'id' which makes the query return only e.g. post IDs.
  • 'id=>parent' which makes the query return only e.g. post IDs and their parent IDs.
  • Anything else, e.g. '', which makes the query return all fields.

Could we try to have the comment enumerate these options? Here's my suggestion:

Which fields to select. Accepts 'ids', which selects just the post ID; 'id=>parent', which selects just the post ID and the post_parent ID; and '', which returns all fields.

@ocean90
4 months ago

#4 @ocean90
4 months ago

  • Keywords needs-refresh removed
  • Milestone changed from Future Release to 5.5

44305.3.diff uses the same format as used in WP_Term_Query.

#5 @davidbaumwald
3 months ago

@ocean90 Is this still doable for 5.5?

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


3 months ago

#7 @SergeyBiryukov
3 months ago

In 48562:

Docs: Improve formatting of the $fields parameter description in WP_Term_Query::__construct().

See #44305, #49572.

#8 @SergeyBiryukov
3 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 48563:

Docs: Correct type and improve description for the $fields parameter of WP_Query::parse_query().

Props ocean90, palmiak, johannadevos, noisysocks.
Fixes #44305.

Note: See TracTickets for help on using tickets.