Make WordPress Core

Opened 6 months ago

Last modified 3 months ago

#60055 new defect (bug)

Array to string conversion warning after r50157

Reported by: dcavins's profile dcavins Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 6.4.2
Component: REST API Keywords: has-patch
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)

60055.01.diff (1.1 KB) - added by dcavins 6 months ago.
Change cleanup logic depending on whether query variable is a string or an array.

Download all attachments as: .zip

Change History (1)

@dcavins
6 months ago

Change cleanup logic depending on whether query variable is a string or an array.

Note: See TracTickets for help on using tickets.