Make WordPress Core

Opened 5 years ago

Closed 19 months ago

#13992 closed enhancement (fixed)

get_terms() has 'search' and 'name__like'

Reported by: dd32 Owned by: wonderboymusic
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has-patch commit
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Both do similar things:

	if ( !empty($name__like) )
		$where .= " AND t.name LIKE '{$name__like}%'";

	if ( !empty($search) ) {
		$search = like_escape($search);
		$where .= " AND (t.name LIKE '%$search%')";

name__like should be removed in favour of search IMO, unless that functionality is intended, and in that case, name__like should get like_escape() applied

Attachments (3)

13992.diff (675 bytes) - added by wojtek.szkutnik 5 years ago.
13992.2.diff (593 bytes) - added by wonderboymusic 20 months ago.
13992.3.diff (1.5 KB) - added by wonderboymusic 19 months ago.

Download all attachments as: .zip

Change History (16)

comment:1 @dd325 years ago

  • Keywords needs-patch added

comment:2 @dd325 years ago

in addition to that, Terms are stored in the database htmlspecialchar'd by the looks of it (ie. '&'), The search should take that into consideration and apply the same filtering to the searching term.

comment:3 @filosofo5 years ago

I would prefer removing 'search' instead, as it's unclear what fields are actually being searched.

comment:4 @dd325 years ago

After thinking a bit more

  • name__like should get escaped, and work as it currently does
  • search should do both name AND slug, Not sure description is worth it?

comment:5 @wojtek.szkutnik5 years ago

  • Cc wojtek.szkutnik@… added
  • Keywords has-patch added; needs-patch removed

@wojtek.szkutnik5 years ago

comment:6 @wojtek.szkutnik5 years ago

  • Keywords gsoc added

Added diff that includes your suggestions, with search looking for name OR slug. No need to include description IMO.

comment:7 @kevinB5 years ago

  • Cc kevinB added

comment:8 @nacin4 years ago

  • Milestone changed from Awaiting Triage to Future Release
  • Type changed from defect (bug) to enhancement

@wonderboymusic20 months ago

comment:9 @wonderboymusic20 months ago

  • Keywords gsoc removed
  • Milestone changed from Future Release to 3.7

Refreshed against trunk, only thing missing from trunk is the search for name AND slug

@wonderboymusic19 months ago

comment:10 @wonderboymusic19 months ago

  • Keywords commit added

.3.diff has unit tests

comment:11 @SergeyBiryukov19 months ago

  • Description modified (diff)

comment:12 @nacin19 months ago

Looks good.

comment:13 @wonderboymusic19 months ago

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

In 25164:

Search term name and slug when the search arg is passed to get_terms(). Adds unit test.

Props wojtek.szkutnik.
Fixes #13992.

Note: See TracTickets for help on using tickets.