Opened 16 years ago
Closed 16 years ago
#8619 closed defect (bug) (fixed)
category_name query fails for multiple-word sub-categories
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (9)
#4
@
16 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
This caused #9643, evidently.
#6
@
16 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
See also #8632. I think the submitter is referring to the same thing, but I am unsure.