• Hi guys! ??

    I have problems with WP_Query for multiple taxonomies, array:

    [tax_query] => Array
            (
                [relation] => AND
                [0] => Array
                    (
                        [taxonomy] => catalogue
                        [field] => slug
                        [include_children] => 1
                        [terms] => Array
                            (
                                [0] => wina
                            )
    
                    )
    
                [1] => Array
                    (
                        [taxonomy] => aoc
                        [field] => slug
                        [terms] => Array
                            (
                                [0] => aoc-xxx
                                [1] => aoc-yyy
                            )
    
                        [operator] => IN
                    )
    
                [2] => Array
                    (
                        [taxonomy] => manufacturer
                        [field] => slug
                        [terms] => Array
                            (
                                [0] => ostrowin
                                [1] => wojnar
                            )
    
                        [operator] => IN
                    )
    
            )

    Situation: I have multiple choice for AOC and Manufacturers. Everything seems fine, until parsing aoc terms. WP_Query has problems with this one.

    Warning: preg_split() expects parameter 2 to be string, array given in /_hosting/_gd/_winamp/wp-includes/query.php on line 1726

    Warning: preg_split() expects parameter 2 to be string, array given in /_hosting/_gd/_winamp/wp-includes/query.php on line 1726

    Lines in WP_Query:

    $tax_query[] = array_merge( $tax_query_defaults, array(
    	'terms' => preg_split( '/[,]+/', $term )
    ) );

    I really don’t know what is going on, manfuacturers are exacly the same taxonomy, and works fine. I must write code in strict mode. I cannot modify core, but it look like this solution works perfectly:

    $tax_query[] = array_merge( $tax_query_defaults, array(
      'terms' => $term //preg_split( '/[,]+/', $term )
    ) );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The warning itself is self explanatory, you cannot use array on the second parameter of preg_split() function for which I assumed it is an array. Your solution is works, because you uncomment the preg_split(), hence directly using the $term.

    Check from where you got the $term from. I’m sure that it is an array so you don’t need to use preg_split() where it is used to split a string into an array.

    Thread Starter Wojnar

    (@wojnar)

    Yes its an array, I know. But like I said – manufacturers has array too, and it works fine. It is exacly the same case, but only names are different.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query – Multiple Taxonomies warning’ is closed to new replies.