Hello I am getting a Error of the WordPress includes, this error appears when I post the multiple values of a taxonomy
<form role="search" method="post" id="searchform" action="<?php echo home_url( '/' ); ?>">
<select name="books[]" multiple>
<option value="a">a</option>
<option value="b">b</option>
</select>
<input type="submit" id="searchsubmit" value="Search" />
</form>
Warning: strpos() expects parameter 1 to be string, array given in www.domain.comwordpresswp-includesquery.php on line 1718
Warning: preg_split() expects parameter 2 to be string, array given in www.domain.comwordpresswp-includesquery.php on line 1719
Warning: Invalid argument supplied for foreach() in www.domain.comwordpresswp-includesquery.php on line 1720
foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
if ( 'post_tag' == $taxonomy )
continue; // Handled further down in the $q['tag'] block
if ( $t->query_var && !empty( $q[$t->query_var] ) ) {
$tax_query_defaults = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
);
if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
$q[$t->query_var] = wp_basename( $q[$t->query_var] );
}
$term = $q[$t->query_var];
if ( strpos($term, '+') !== false ) {
$terms = preg_split( '/[+]+/', $term );
foreach ( $terms as $term ) {
$tax_query[] = array_merge( $tax_query_defaults, array(
'terms' => array( $term )
) );
}
} else {
$tax_query[] = array_merge( $tax_query_defaults, array(
'terms' => preg_split( '/[,]+/', $term )
) );
}
}
}
The error does not appear when I post it to searchresults.php or when I use when I use a single value or a none taxonomy name;
<select name="books">
<select name="NoneTaxonomyName[]" multiple>
does someone know how to resolve this?
As I said in a comment above, setting
query_var => false
for the custom taxonomy is not a solution because this will make term pages in frontend return a 404 error. Renounce to term pages in the frontend to make a simple form to work is far away to be a solution.Finally I’ve solved the problem. Instead of set the name in the select element to ‘my_tax[]’, I’ve set it to something like ‘tax_input[‘my_tax’][]. Don’t ask me why WordPress needs this, but it fix the problem.
Just if someone needs an example.
My sample taxonomies:
Here a sample form:
Added a custom query var:
An my sample pre_get_posts:
solved with; query_var => false