This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Multisite Search

#37624
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

That actually might be possible via a custom code snippet. All you need to know is the blog ID and the taxonomy term ID for which you want to restrict the results to.

I have constructed a small snippet, which should do that, you only need to plug the values to the $include variable. On the left side is the blog ID, on the right side is the category to include the results for that blog.

Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

add_filter("asp_query_args", "asp_query_args_change", 10, 2);
function asp_query_args_change($args, $search_id) {
	$include = array(
		// Blog ID => Taxonomy term ID
		1 => 11,
		2 => 22,
	);
	if ( isset($include[get_current_blog_id()]) ) {
		$args['post_tax_filter'] = array(
			array(
				'taxonomy'  => 'category',
				'include'   => array($include[get_current_blog_id()]), 
				'exclude'   => array(),
				'allow_empty' => false // Don't allow results, which does not have connection with this taxonomy
			)
		);
	}
  return $args;
}