Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search specific pages
- This topic has 6 replies, 2 voices, and was last updated 9 years, 11 months ago by
alexpopa.
-
AuthorPosts
-
June 29, 2016 at 5:24 am #9298
alexpopa
ParticipantCan I setup Ajax Search to search ONLY through a few selected pages? How can i restrict the search to only 4 pages that I want it to search for a specific instance.
June 29, 2016 at 11:40 am #9308Ernest Marcinko
KeymasterHi!
Well, there is no option for that, but it is possible by using a small custom snippet if you are using plugin version 4.9.0 or further.
Try putting this code to the functions.php file in your active theme directory:
Don’t forget to change the numbers 1, 2, 3, 4 to the page IDs you want to restrict the search to.
June 29, 2016 at 7:07 pm #9311alexpopa
ParticipantSweet, I updated to the latest version and added the filter in functions.php and it works like a charm!
However, what’s the recommended logic to make sure its only affecting one of the search instances (I have multiple instances of ajax search on the website, I only want one to reflect those pages because its my services page …)
You can be specific, or general, I’m a dev.
June 29, 2016 at 7:10 pm #9312Ernest Marcinko
KeymasterGreat!
In that case the $id in the arguments list is actually the search id, so you can change the $args line accordingly:
[php]if ( $id == 1 )
$args["post_in"] = array(1, 2, 3, 4);[/php]..and basically that’s it, that should do the trick.
June 29, 2016 at 8:16 pm #9315alexpopa
ParticipantThat would have been sweet if it worked 🙂
Really quick two things — i really appreciate your help:
1) I tried adding the logic for $id but it didn’t work, so I pulled up the logs and found this:
PHP Warning: Missing argument 2 for asp_include_only_ids(), called in /var/www/northshoreitme/wp-includes/plugin.phpApparently $id isn’t passed perhaps?
2) It seems (maybe) since the update ajax search doesn’t work on mobile (iPhone) works fine on desktop.
Here are the links to check, I can make you a username/pass if you need to look closer later on. You can type “test” or “web” and the reasults should populate.http://northshoreit.me/services/
http://northshoreit.me/oops/June 29, 2016 at 8:43 pm #9316Ernest Marcinko
Keymaster1. I think you need to change the filter statement as well, to pass the second parameter, like so:
[php]add_filter( ‘asp_query_args’, ‘asp_include_only_ids’, 2, 2 );[/php]
2. It works on my end, tried on 2 devices. Maybe it’s just the browser/site cache?
June 29, 2016 at 9:38 pm #9317alexpopa
ParticipantSweet, that fixed it, I forgot which one was first for add_filter, priority or parameters.
In terms of the iPhone I’ll keep an eye on it I’ll try it in the simulator. I opened a private browsing mode on my iPhone and it didn’t work but I will look a little deeper and report back.
Thanks again Ernest, great plugin.
-
AuthorPosts
- The topic ‘Search specific pages’ is closed to new replies.