Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search pages ONLY in parent category
This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko 3 years, 11 months ago.
- AuthorPosts
- June 27, 2019 at 12:26 pm #23456
Hi,
Please could you help me setup the search so that I can have only results in a parent category are displayed in the results?
For example the search box is displayed on the Parent page ‘Synergy’ http://scancert.co.uk/synergy/
I would like the results displayed from this form to ONLY include child pages under the parent ‘Synergy’ for example: searching 23 would load the results such as http://scancert.co.uk/synergy/03e023/ and http://scancert.co.uk/synergy/23e001/ but not http://scancert.co.uk/lynch/2332/
If you could please advise me the best way to do this I would be extremely grateful.
Many Thanks,
Sam
June 27, 2019 at 12:43 pm #23458Hi Sam,
This might be possible via a custom code. There is a knowledge base on how to get results for specific page parent IDs. If I understand correctly, you have parent/child pages, and you only need the child pages within the results?
In that case, via a minor modification to the original custom code, this should do the trick:
(Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!)
Best,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. */ $id = get_the_ID(); if ( !empty($id) ) $args['post_parent'] = array($id); return $args; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.