I am creating a custom search form which will search a custom post type called recipes. and it has a load of taxonomies.
Now I output these taxonomy's terms into checkboxes which are grouped by the taxonomy name.
The issue is on the input:
<!-- language: lang-html -->
<label><input type="checkbox" name="epx_recipes_season[]" value="autumn">Autumn</label>
<label><input type="checkbox" name="epx_recipes_season[]" value="spring">Spring</label>
<label><input type="checkbox" name="epx_recipes_season[]" value="summer-3">Summer</label>
<label><input type="checkbox" name="epx_recipes_season[]" value="winter-3">Winter</label>
<label><input type="checkbox" name="epx_recipes_course[]" value="breakfast-3">Breakfast</label>
<label><input type="checkbox" name="epx_recipes_course[]" value="brunch-2">Brunch</label>
<label><input type="checkbox" name="epx_recipes_course[]" value="dessert">Dessert</label>
<label><input type="checkbox" name="epx_recipes_course[]" value="dinner">Dinner</label>
<label><input type="checkbox" name="epx_recipes_course[]" value="light-meals-2">Light Meals</label>
<label><input type="checkbox" name="epx_recipes_course[]" value="lunch-3">Lunch</label>
<label><input type="checkbox" name="epx_recipes_requirements[]" value="diary-free">Diary free</label>
<label><input type="checkbox" name="epx_recipes_requirements[]" value="egg-free">Egg Free</label>
<label><input type="checkbox" name="epx_recipes_requirements[]" value="gluten-free-3">Gluten Free</label>
<label><input type="checkbox" name="epx_recipes_requirements[]" value="nut-free">Nut Free</label>
<label><input type="checkbox" name="epx_recipes_requirements[]" value="shellfish-free">Shellfish free</label>
<label><input type="checkbox" name="epx_recipes_requirements[]" value="vegitarians">vegitarians</label>
<label><input type="checkbox" name="epx_recipes_cuisines[]" value="american">American</label>
<label><input type="checkbox" name="epx_recipes_cuisines[]" value="british-3">British</label>
<label><input type="checkbox" name="epx_recipes_cuisines[]" value="greek-3">Greek</label>
<label><input type="checkbox" name="epx_recipes_cuisines[]" value="irish">Irish</label>
<label><input type="checkbox" name="epx_recipes_cuisines[]" value="italian">Italian</label>
<label><input type="checkbox" name="epx_recipes_cuisines[]" value="mexican-3">Mexican</label>
<label><input type="checkbox" name="epx_recipes_occastions[]" value="birthdays">Birthdays</label>
<label><input type="checkbox" name="epx_recipes_occastions[]" value="christmas">Christmas</label>
<label><input type="checkbox" name="epx_recipes_occastions[]" value="easter-3">Easter</label>
<label><input type="checkbox" name="epx_recipes_occastions[]" value="fathers-day-2">Fathers Day</label>
<label><input type="checkbox" name="epx_recipes_occastions[]" value="mothers-day-2">Mothers day</label>
<label><input type="checkbox" name="epx_recipes_occastions[]" value="valentines">Valentines</label>
The issue comes from the name they have to keep the grouped together they have a [] so when posted it goes as array which i can then parse. this issue is WordPress is reading the form straight away and outputting the following error message.
Notice: Array to string conversion in /home/sites/epixdev1.co.uk/public_html/htk2014/wp-includes/query.php on line 1858
Warning: preg_split() expects parameter 2 to be string, array given in /home/sites/epixdev1.co.uk/public_html/htk2014/wp-includes/query.php on line 1867
Notice: Array to string conversion in /home/sites/epixdev1.co.uk/public_html/htk2014/wp-includes/query.php on line 1858
Warning: preg_split() expects parameter 2 to be string, array given in /home/sites/epixdev1.co.uk/public_html/htk2014/wp-includes/query.php on line 1867
Notice: Trying to get property of non-object in /home/sites/epixdev1.co.uk/public_html/htk2014/wp-content/plugins/wordpress-seo/frontend/class-opengraph.php on line 524
Here the code that makes the form
<!-- language: lang-php -->
//Will be used to output the advanced search box
function epix_recipes_search(){
//Need to run each different type of taxonmies
//How Many there are
$noTax = 6;
//The Taxonomies
$taxonomies = array('epx_recipes_season','epx_recipes_course','epx_recipes_requirements','epx_recipes_cuisines','epx_recipes_occastions','epx_recipes_typeofcooking');
//need the basic output varible
$output = "";
//Need to build a basic form
$output .= '<form method="post" id="searchform" action="/recipes/">'."\r\n";
//Now a Basic Search box
$output .= ' <h2>Keyword Search</h2>'."\r\n";
$output .= ' <input type="text" class="field" name="s" id="s" size="19" placeholder="Search" />'."\r\n";
//Now need to Show the Advance Search Area
$output .= ' <h2>Advanced Filters</h2>'."\r\n";
//Now need to run the system for each Taxonomies
foreach ( $taxonomies as $tax ) {
//Need to get the name of each TAX
//What Taxonomy we want to check
$args=array(
'name' => $tax
);
$outputtype = 'objects'; // or objects
$taxonomieslist=get_taxonomies($args,$outputtype);
if ($taxonomieslist) {
foreach ($taxonomieslist as $taxonomiesone ) {
$output .= ' <h3>'. $taxonomiesone->labels->name. '</h3>'."\r\n";
}
}
//now get the terms in the Taxonomies
$output .= epix_recipes_taxterms($tax);
}
//now need to end the form with the correct sytack
//First a submit button
$output .= ' <input type="submit" class="submit" name="submit" id="searchsubmit" value="submit" />'."\r\n";
//Now the closing for tag
$output .= '</form'."\r\n";
//Need to return the form
return $output;
}
//This will get the taxonomies terms
function epix_recipes_taxterms($tax){
//Need to get each term and return it
$returnoutput = "";
$terms = get_terms($tax,'hide_empty=0');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
//$returnoutput .= " <select name=".$tax.">"."\r\n";
$i = 0;
foreach ( $terms as $term ) {
$returnoutput .= ' <label><input type="checkbox" name="'.$tax.'[]" value="'.$term->slug.'">' . $term->name . '</label>'."\r\n";
//$i++;['.$i.']
}
//$returnoutput .= " </select>"."\r\n";
}
return $returnoutput;
}
If anyone can help me work out why this is happening, or a way to stop WordPress giving out these errors that would be really helpful.
Yes I have WordPress debug on!