Opened 11 years ago
Closed 11 years ago
#32454 closed defect (bug) (fixed)
WP_Query->parse_tax_query() can't handle arrays from URL querystring
| Reported by: | Veraxus | Owned by: | johnbillion |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.3 |
| Component: | Query | Version: | 3.1 |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: | Focuses: |
Description
When using querystring variables to filter taxonomies (default WordPress behavior) WP_Query->parse_tax_query() assumes it's getting a string from the URL (?tax=1,2,3,4).
However, if using HTML form-based filtering, such as a checkbox list, an array is passed instead. When this happens, not only does the search/filter not work, a slew of warnings are generated since WP_Query->parse_tax_query() is only capable of handling strings.
Fortunately, this is easily fixed with just three lines. If the array is detected and imploded before being handled, everything works as expected/designed without generating any errors or warnings.
Patch file is attached.
Attachments (3)
Change History (16)
#1
@
11 years ago
- Keywords has-patch needs-testing needs-unit-tests added
- Version trunk → 3.1
Thanks for the patch Veraxus.
This will need unit tests to show that it fixes the issue at hand and that it doesn't have any unintended side effects.
#2
@
11 years ago
I've included unit tests for single term and multi-term use cases.
Pre-patch:
- Single term unit test passes
- Multi-term unit test fails (error)
With patch:
- Single term unit test passes
- Multi-term unit test passes
#3
@
11 years ago
- Keywords needs-unit-tests removed
Is anything else needed for this? It would be ideal if we got this bug squished before 4.3
#7
@
11 years ago
@boonebgorges Looks like the PHPUnit tests doesn't pass in PHP > 5.2, see https://travis-ci.org/aaronjorbin/develop.wordpress/builds/69794056.
#8
@
11 years ago
Taking a look... although at upload time I ran the tests successfully on 5.2.16 and 5.6.9
#9
follow-up:
↓ 10
@
11 years ago
- Resolution fixed
- Status closed → reopened
I think replacing assertEquals() with assertEqualSets() should fix this, see 32454-ut.patch.
#10
in reply to: ↑ 9
@
11 years ago
Replying to ocean90:
I think replacing
assertEquals()withassertEqualSets()should fix this, see 32454-ut.patch.
I'm not able to reproduce the errors on 5.3, 5.4, 5.5, or 5.6 with the latest trunk - and I manually checked the values being passed to assertEquals() as well.
Generally speaking, assertEqualSets() shouldn't be necessary… unless wp_list_pluck() is returning it's array out of order for some reason. It's a safe alternative in this case, at least.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
parse_tax_query() correctly detects & implodes arrays