Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Multiple search widgets
- This topic has 11 replies, 2 voices, and was last updated 5 years, 10 months ago by
phantomowl10.
-
AuthorPosts
-
July 2, 2020 at 8:15 pm #28235
phantomowl10
ParticipantHi 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
July 3, 2020 at 8:58 am #28238Ernest Marcinko
KeymasterHi,
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.
July 10, 2020 at 4:13 pm #28380phantomowl10
ParticipantHi 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,
CamJuly 10, 2020 at 4:21 pm #28381phantomowl10
ParticipantHi 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.
July 11, 2020 at 7:28 am #28387Ernest Marcinko
KeymasterHi,
If the subdirectory is not part of the same WordPress installation, then there is no possible way.
July 14, 2020 at 6:16 am #28438phantomowl10
ParticipantIts 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
July 14, 2020 at 8:16 am #28442Ernest Marcinko
KeymasterHi,
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.July 15, 2020 at 3:58 pm #28505phantomowl10
ParticipantThis 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;
}July 16, 2020 at 8:12 am #28511Ernest Marcinko
KeymasterTo 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.
July 17, 2020 at 3:30 pm #28546phantomowl10
ParticipantThat’s perfect – thanks for your help.
July 18, 2020 at 9:26 am #28555Ernest Marcinko
KeymasterYou cannot access this content.
July 18, 2020 at 3:03 pm #28568phantomowl10
ParticipantYes, please go ahead and close the ticket – thanks!
-
AuthorPosts
- The topic ‘Multiple search widgets’ is closed to new replies.