Hi Nigel,
Thanks for the reply,
The various parameters in the search URL refer to custom taxonomies set up in Toolset Types. These are used with a tax_query in WP_Query to select the custom post types that match the taxonomies/search.
I have included the WP_Query code below:
$search_box = $_GET['s'];
$expert_service = $_GET['expert-service'];
$regional_experience = $_GET['regional-experience'];
$sector_experience = $_GET['sector-experience'];
$language = $_GET['language'];
$location = $_GET['location'];
$tax_query = array('relation' => 'AND');
if (!empty($expert_service))
{
$tax_query[] = array(
'taxonomy' => 'expert-service',
'field' => 'slug',
'terms' => $expert_service
);
}
if (!empty($regional_experience))
{
$tax_query[] = array(
'taxonomy' => 'regional-experience',
'field' => 'slug',
'terms' => array_values($regional_experience),
'operator' => 'AND',
);
}
if (!empty($sector_experience))
{
$tax_query[] = array(
'taxonomy' => 'sector-experience',
'field' => 'slug',
'terms' => array_values($sector_experience),
'operator' => 'AND',
);
}
if (!empty($language))
{
$tax_query[] = array(
'taxonomy' => 'language',
'field' => 'slug',
'terms' => array_values($language),
'operator' => 'AND',
);
}
if (!empty($location))
{
$tax_query[] = array(
'taxonomy' => 'location',
'field' => 'slug',
'terms' => $location
);
}
add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
//Query for meta_query and tax_query
$q1 = new WP_Query(
array(
'post_type' => 'expert-post',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'expert_keywords',
'value' => $search_box,
'compare' => 'LIKE'
)
),
'orderby' => array(
'posts_orderby_lastname' => 'ASC',
),
'tax_query' => $tax_query,
'fields' => 'ids'
)
);
//A separate query for 's' parameter. You can't use the 's' parameter with meta_query.
$q2 = new WP_Query(
array(
'post_type' => 'expert-post',
'posts_per_page' => -1,
'orderby' => array(
'posts_orderby_lastname' => 'ASC',
),
's' => $search_box,
'tax_query' => $tax_query,
'fields' => 'ids'
)
);
$allTheIDs = array_unique(array_merge($q1->posts, $q2->posts));
if(empty($allTheIDs)){
$allTheIDs = array(0);
}
//Merge the two WP_Query results
$query = new WP_Query(array(
'post_type' => 'expert-post',
'post__in' => $allTheIDs,
'posts_per_page' => -1,
'orderby' => array(
'posts_orderby_lastname' => 'ASC',
),
));
The fields/taxonomies added to the search filters are added using dropdowns. There was a javascript plugin added that allowed you to multi select in the dropdowns but this was removed due to the TypeError. I believe it worked similar to using checkboxes so multiple options can be added to the GET request. e.g. ®ional-experience[]=asia®ional-experience[]=americas
Also, the expert search isn't actually using the default WordPress search template so this could possibly be part of the problem.
In search.php we have the following code:
<?php
$search_refer = $_GET["site_section"];
$search_refer_product = $_GET["post_type"];
$search_refer_knowledge = $_GET["post_knowledge"];
if ($search_refer_product == 'expert') { load_template(TEMPLATEPATH . '/search-expert-post.php'); }
else if ($search_refer == 'site-search') { load_template(TEMPLATEPATH . '/search-site.php'); }
else if ($search_refer_knowledge == 'knowledge-document') { load_template(TEMPLATEPATH . '/search-knowledge-document.php'); }
?>
When the expert search is submitted it is sent with $_GET["post_type"] set as "expert" and a different template is loaded in '/search-expert-post.php'. This template/page then includes the WP_Query code above.
Let me know if you need any further details.
Thanks