WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 7 months ago

#44305 assigned defect (bug)

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

Reported by: ocean90 Owned by: johannadevos
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Query Keywords: good-first-bug has-patch needs-refresh
Focuses: docs Cc:
PR Number:

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 (2)

44305.diff (2.1 KB) - added by palmiak 17 months ago.
44305.2.diff (1.5 KB) - added by johannadevos 7 months ago.
Second patch that fixes whitespace and removes an irrelevant description

Download all attachments as: .zip

Change History (5)

@palmiak
17 months ago

#1 @noisysocks
16 months ago

  • Keywords has-patch added; needs-patch removed

#2 @johannadevos
7 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
7 months ago

Second patch that fixes whitespace and removes an irrelevant description

#3 @noisysocks
7 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.
Note: See TracTickets for help on using tickets.