Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#57996 closed enhancement (fixed)

Change $search_columns type from array to string[].

Reported by: tmatsuur's profile tmatsuur Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.2.1 Priority: normal
Severity: normal Version: 6.2
Component: Query Keywords: fixed-major
Focuses: docs Cc:

Description

The type of $search_columns added in version 6.2 is 'array'.

	 *     @type array           $search_columns          Array of column names to be searched. Accepts 'post_title',
	 *                                                    'post_excerpt' and 'post_content'. Default empty array.

I think 'string[]' would be more appropriate for this 'array' to match other parameters.

	 *     @type string[]        $search_columns          Array of column names to be searched. Accepts 'post_title',
	 *                                                    'post_excerpt' and 'post_content'. Default empty array.

This parameter is also converted to an array if it is not an array.

$search_columns         = ! empty( $q['search_columns'] ) ? $q['search_columns'] : $default_search_columns;
if ( ! is_array( $search_columns ) ) {
	$search_columns = array( $search_columns );
}

In light of the above, "string|string[]" would be better than "string[]".

	 *     @type string|string[] $search_columns          A column name (string) or array of column names to be searched.
	 *                                                    Accepts 'post_title', 'post_excerpt' and 'post_content'.
	 *                                                    Default empty array.

Change History (6)

#1 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 6.2.1

Thanks for the ticket!

The search_columns parameter is already documented as string[] in WP_User_Query as of [49693], and in WP_Site_Query as of [51184], so it definitely makes sense for WP_Query too. Introduced in [55248].

To match the above two classes, I think string[] would be preferable here, rather than string|string[]. While a string can technically be passed too, we should encourage passing an array for consistency.

#2 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 55597:

Docs: Use typed array notation for search_columns in WP_Query::parse_query().

Follow-up to [55248].

Props tmatsuur.
Fixes #57996.

#3 follow-up: @SergeyBiryukov
2 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 6.2.1 consideration.

#4 in reply to: ↑ 3 @tmatsuur
2 years ago

Replying to SergeyBiryukov:

Reopening for 6.2.1 consideration.

Thanks @SergeyBiryukov

#5 @SergeyBiryukov
2 years ago

  • Type changed from feature request to enhancement

#6 @SergeyBiryukov
2 years ago

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

In 55640:

Docs: Use typed array notation for search_columns in WP_Query::parse_query().

Follow-up to [55248].

Props tmatsuur.
Merges [55597] to the 6.2 branch.
Fixes #57996.

Note: See TracTickets for help on using tickets.