Search specific pages

This topic contains 6 replies, has 2 voices, and was last updated by

 
Participant
5 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9298

    Participant

    Can 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.

    #9308

    Hi!

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #9311

    Participant

    Sweet, 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.

    #9312

    Great!

    In that case the $id in the arguments list is actually the search id, so you can change the $args line accordingly:

    if ( $id == 1 )
        $args["post_in"] = array(1, 2, 3, 4);

    ..and basically that’s it, that should do the trick.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #9315

    Participant

    That 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.php

    Apparently $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/

    #9316

    1. I think you need to change the filter statement as well, to pass the second parameter, like so:

    add_filter( 'asp_query_args', 'asp_include_only_ids', 2, 2 );

    2. It works on my end, tried on 2 devices. Maybe it’s just the browser/site cache?

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #9317

    Participant

    Sweet, 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.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Search specific pages’ is closed to new replies.