WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#8619 closed defect (bug) (fixed)

category_name query fails for multiple-word sub-categories

Reported by: filosofo Owned by: ryan
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: General Keywords: has-patch tested category_name query_posts get_category_by_path
Focuses: Cc:

Description

Suppose you have a category named "I am sub category". Its URL looks something like this:

example.com/grandparent/parent/i-am-sub-category/

When you query for the sub-category using category_name, like so

query_posts(array('category_name' => 'I am sub category'));

the query calls get_category_by_path() on 'I am sub category' first with the default of "full match" set to true, which returns null because the full match would include the parent and grandparent category names, as above.

By the time the query gets around to calling get_category_by_path() again, this time with full match set to false, it has stripped the spaces from it, so that it searches for 'iamsubcategory' which it won't find.

The solution is to sanitize the category name from the start so the spaces are handled correctly.

Attachments (2)

sub_category_w_spaces.diff (570 bytes) - added by filosofo 5 years ago.
sub_category_w_spaces_take_2.8619.diff (611 bytes) - added by filosofo 5 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 minusonebit5 years ago

See also #8632. I think the submitter is referring to the same thing, but I am unsure.

comment:2 markjaquith5 years ago

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

(In [10956]) Sanitize when querying against category name so that multiple-word subcategories match. props filosofo. fixes #8619

comment:3 ryan5 years ago

(In [11085]) Revert [10956]. fixes #9643 see #8619

comment:4 ryan5 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

This caused #9643, evidently.

comment:5 mtekk5 years ago

  • Keywords needs-patch added; has-patch removed

comment:6 filosofo5 years ago

  • Keywords has-patch tested added; needs-patch removed
  • Owner changed from anonymous to ryan
  • Status changed from reopened to new

Sorry about that. I was using sanitize_title because that's what get_category_by_path does. However, I'd failed to note that get_category_by_path splits the path into "leaves" delimited by slashes, and sanitizes the leaves individually.

Latest patch does that and corrects the original problem without causing #9643

comment:7 ryan5 years ago

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

(In [11121]) Sanitize when querying against category name so that multiple-word subcategories match. props filosofo. fixes #8619

Note: See TracTickets for help on using tickets.