Multiple search widgets

This topic contains 11 replies, has 2 voices, and was last updated by phantomowl10 phantomowl10 3 years, 9 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #28235
    phantomowl10
    phantomowl10
    Participant

    Hi there,

    As we have many gated/password protected sections on our site, we need to create multiple search widgets and embed them within

    Each search widget needs to only be able to index/search specific pages.

    How can I achieve this?

    Thanks

    #28238
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Well, you can create as many search bars as you want, and configure them accordingly. Use the exclusion/inclusion options to change what items you want to restrict or allow.

    Best,
    Ernest Marcinko

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


    #28380
    phantomowl10
    phantomowl10
    Participant

    Hi Ernest,

    Thanks for confirming – I see now how to duplicate the search bars.

    Question though: how do I one up to only include searches from a subdomain, i.e. /n-spro/

    Thanks,
    Cam

    #28381
    phantomowl10
    phantomowl10
    Participant

    Hi Ernest,

    Further to my note: I see how to include via tags, categories, etc but I’m looking to only include Pages from specific subdiretories.

    #28387
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    If the subdirectory is not part of the same WordPress installation, then there is no possible way.

    Best,
    Ernest Marcinko

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


    #28438
    phantomowl10
    phantomowl10
    Participant

    Its all part of the WP install; maybe more accurately, we would need a different search form for parent pages and their child pages, not a subdirectory.

    So, for example, a search form on https://mindmgt.com/client-name/ that would only show results from its child pages:

    https://mindmgt.com/client-name/sleep/
    https://mindmgt.com/client-name/work/
    https://mindmgt.com/client-name/

    etc

    #28442
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    You can use the exclusion option for that then.
    In your case, maybe this knowledge base would be even better. That lets you limit results to pages with a specific parent ID. One thing to note – that parent > child related exclusions does not work on multiple levers, like parent > child > grandchild etc.. because only direct page connections are stored in the wp database. For that, categorizing and excluding/including by categories is much better.

    Best,
    Ernest Marcinko

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


    #28505
    phantomowl10
    phantomowl10
    Participant

    This makes sense and I’ve applied it to one parent page for parent ID 468. My question is now, how do I add multiple instances of this filter? For example, you’ll see that I’ve got the correctly-working filter set up for a client named NSPRO, parent ID 468. I’ve tested this and the search bar only returns the desired results.

    However, if I add a second instance for a client named Accompass – see below – it breaks functions.php:

    // — NSPRO —

    add_filter( ‘asp_query_args’, ‘asp_include_only_parent_ids’, 10, 2 );

    function asp_include_only_parent_ids( $args, $id ) {
    /**
    * Enter the post/cpt prent IDs here. The results will be
    * limited to objects with these parent IDs.
    */
    $ids = array(468);
    /**
    * Search instance IDs you want this code to apply on.
    */
    $search_ids = array(1);

    // ————————————————–
    // ————————————————–
    // — !! Do not change anything below this line !! —
    // ————————————————–
    if ( in_array($id, $search_ids) )
    $args[‘post_parent’] = $ids;

    return $args;
    }

    // — accompass —

    add_filter( ‘asp_query_args’, ‘asp_include_only_parent_ids’, 10, 2 );

    function asp_include_only_parent_ids( $args, $id ) {
    /**
    * Enter the post/cpt prent IDs here. The results will be
    * limited to objects with these parent IDs.
    */
    $ids = array(517);
    /**
    * Search instance IDs you want this code to apply on.
    */
    $search_ids = array(2);

    // ————————————————–
    // ————————————————–
    // — !! Do not change anything below this line !! —
    // ————————————————–
    if ( in_array($id, $search_ids) )
    $args[‘post_parent’] = $ids;

    return $args;
    }

    #28511
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    To apply the code multiple times, you will have to rename the function, like this:

    add_filter( 'asp_query_args', 'asp_include_only_parent_ids2', 10, 2 );
    function asp_include_only_parent_ids2( $args, $id ) {

    Putting a number after the function name will work just fine. Make sure to change the function name in the preceeding add_filter statement as well.

    Best,
    Ernest Marcinko

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


    #28546
    phantomowl10
    phantomowl10
    Participant

    That’s perfect – thanks for your help.

    #28555
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


    #28568
    phantomowl10
    phantomowl10
    Participant

    Yes, please go ahead and close the ticket – thanks!

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

The topic ‘Multiple search widgets’ is closed to new replies.