Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Multisite Search
This topic contains 7 replies, has 2 voices, and was last updated by Ernest Marcinko 10 months, 4 weeks ago.
- AuthorPosts
- April 20, 2022 at 2:12 pm #37582
Hi,
I would like to find out, is there some way to make a multisite search within a specific category only?
ThanksApril 20, 2022 at 5:04 pm #37601Hi,
I’m afraid that would not work, because on each subsite the category IDs are different. I can suggest adding a category restrition programmatically, but if you are searching more than 1 subsite, it will try to get results from that category ID on all of them, and since that ID does not exist (or belong to another category) on the subsites, the results will be inconsistent and missing.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 20, 2022 at 5:10 pm #37602Hi,
Thank you.
Well actually all subsites will be only searching the main site and not each other. So we basically have company listings on the main site, and we have subsites based on country. So i would want the USA subsite to only search the main site within the USA category. Would this be possible?
Thanks so much!April 22, 2022 at 2:16 pm #37624Hi,
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.
Best,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; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 22, 2022 at 2:45 pm #37626Awesome! Thank you so much! i will try it and let you know if it worked.
April 25, 2022 at 12:32 pm #37632You are very welcome 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 3, 2022 at 2:53 pm #37703Hi,
Thanks so much for the code, but unfortunately it does not seem to be working. Im not getting any errors but its still showing other categories.
I did minor changes to the code:
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 => 269 ); if ( isset($include[get_current_blog_id()]) ) { $args['post_tax_filter'] = array( array( 'taxonomy' => 'listing_location', 'post_type' => 'listing', '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; }
i think i did it right based on this: wp-admin/edit-tags.php?taxonomy=listing_location&post_type=listing
And this is the link to that category: search/?postType=listing&listing_location=268
Any help would be greatly appreciated.
Thanks so much!
May 5, 2022 at 12:29 pm #37721I may need to test this directly. Can you add temporary FTP and back-end access?
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.