Opened 9 months ago
Last modified 3 months ago
#60055 new defect (bug)
Array to string conversion warning after r50157
Reported by: | dcavins | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | 6.4.2 |
Component: | REST API | Keywords: | has-patch reporter-feedback |
Focuses: | Cc: |
Description
When using the new REST API feature that allows one to add the include_children
parameter to a taxonomy-term-filtered request, like
const query = { categories: { terms: [ 3, 5, 7 ], include_children: true, }, };
(example taken from https://make.wordpress.org/core/2021/02/23/rest-api-changes-in-wordpress-5-7/)
I'm encountering the warning:
PHP Warning: Array to string conversion in /Users/cavinsd/Local Sites/caresnet/app/public/wp-includes/class-wp.php on line 361
The error refers to this line:
$this->query_vars[ $t->query_var ] = str_replace( ' ', '+', $this->query_vars[ $t->query_var ] );
which is expecting a flat taxonomy parameter, not a multidimensional array.
Thanks for adding the include_children
parameter; it makes working with the REST API much simpler in some cases!
Attachments (1)
Change History (2)
#1
@
3 months ago
- Keywords reporter-feedback added
When I use a query like the one in the example, I cannot replicate the issue, at least not with a standard WordPress setup. Here are the queries I've tested:
1. wp/v2/posts?categories%5Bterms%5D%5B0%5D=1&categories%5Bterms%5D%5B1%5D=2&categories%5Bterms%5D%5B2%5D=4&categories%5Binclude_children%5D=1 2. wp/v2/posts?categories%5Bterms%5D%5B0%5D=3&categories%5Bterms%5D%5B1%5D=5&categories%5Bterms%5D%5B2%5D=7&categories%5Binclude_children%5D=true
I am curious to know the exact query used to reproduce the issue.
Change cleanup logic depending on whether query variable is a string or an array.