• Hi

    I would like to have 2 search widgets on my website. I would like one to search my pages and one to search my posts. I’ve found lots of documentation on the web which helps you do one or the other but nothing where you can have 2 on the same site. Any help with this would be great.

Viewing 5 replies - 16 through 20 (of 20 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this: https://pastebin.com/a2vPrSk2
    I’ve commented my contributions with // my code

    Thread Starter duncmorley

    (@duncmorley)

    That works like a treat. Thank you very much for all you help with this.

    Do you think this plugin would be worth submitting. From what I could see there wasn’t anything out there that did what this does… but I may be wrong.

    Moderator keesiemeijer

    (@keesiemeijer)

    I would test it more thoroughly before submitting. and maybe change this

    // my code 1
    add_filter('pre_get_posts', array($this,'mySearchFilter'));

    to:

    // my code 1
    if(isset($_GET['post_type']) && $_GET['post_type']) {
    add_filter('pre_get_posts', array($this,'mySearchFilter'));
    }

    So you would only add a filter to the query when there was a $_GET[‘post_type’] submitted.

    I would also prefix it so you don’t confllict with other plugins widgets: “post_type” to “spt_post_type”.

    This is awesome. I have been looking to do the exact same thing. Did you submit this plugin? I would love to use it.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Multiple search boxes on one site’ is closed to new replies.