Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#44305 closed defect (bug) (fixed)

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

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

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 8 years ago.
44305.2.diff​ (1.5 KB ) - added by johannadevos 8 years ago.
Second patch that fixes whitespace and removes an irrelevant description
44305.3.diff​ (1.5 KB ) - added by ocean90 6 years ago.

Download all attachments as: .zip

Change History (11)

#1 @noisysocks
8 years ago

  • Keywords has-patch added; needs-patch removed

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

Second patch that fixes whitespace and removes an irrelevant description

#3 @noisysocks
8 years ago

  • Keywords needs-refresh added
  • Owner set to johannadevos
  • Status new → 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.

#4 @ocean90
6 years ago

  • Keywords needs-refresh removed
  • Milestone Future Release → 5.5

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

#5 @davidbaumwald
6 years ago

@ocean90 Is this still doable for 5.5?

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


6 years ago

#7 @SergeyBiryukov
6 years ago

In 48562:

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

See #44305, #49572.

#8 @SergeyBiryukov
6 years ago

  • Resolution → fixed
  • Status assigned → 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.