Make WordPress Core

Opened 5 years ago

Closed 2 years 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 2 years ago.
13992.3.diff (1.5 KB) - added by wonderboymusic 2 years ago.

Download all attachments as: .zip

Change History (16)

#1 @dd32
5 years ago

  • Keywords needs-patch added

#2 @dd32
5 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.

#3 @filosofo
5 years ago

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

#4 @dd32
5 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?

#5 @wojtek.szkutnik
5 years ago

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

#6 @wojtek.szkutnik
5 years ago

  • Keywords gsoc added

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

#7 @kevinB
5 years ago

  • Cc kevinB added

#8 @nacin
5 years ago

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

#9 @wonderboymusic
2 years 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

#10 @wonderboymusic
2 years ago

  • Keywords commit added

.3.diff has unit tests

#11 @SergeyBiryukov
2 years ago

  • Description modified (diff)

#12 @nacin
2 years ago

Looks good.

#13 @wonderboymusic
2 years 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.