Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Multisite Search
- This topic has 7 replies, 2 voices, and was last updated 4 years, 1 month ago by
Ernest Marcinko.
-
AuthorPosts
-
April 20, 2022 at 2:12 pm #37582
Sittingduck
ParticipantHi,
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 #37601Ernest Marcinko
KeymasterHi,
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.
April 20, 2022 at 5:10 pm #37602Sittingduck
ParticipantHi,
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 #37624Ernest Marcinko
KeymasterHi,
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; }April 22, 2022 at 2:45 pm #37626Sittingduck
ParticipantAwesome! Thank you so much! i will try it and let you know if it worked.
April 25, 2022 at 12:32 pm #37632Ernest Marcinko
KeymasterYou are very welcome 🙂
May 3, 2022 at 2:53 pm #37703Sittingduck
ParticipantHi,
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 #37721Ernest Marcinko
KeymasterI may need to test this directly. Can you add temporary FTP and back-end access?
-
AuthorPosts
- You must be logged in to reply to this topic.