- This topic has 1 reply, 2 voices, and was last updated 7 years, 11 months ago by Ernest Marcinko.
-
AuthorPosts
-
September 28, 2016 at 1:32 pm #10278rosariagandarParticipant
Hi there,
I am wanting to showcase only a select set of pages within the search results, specifically only pages that have the term ‘support’ in the url.
Is this possible? Or is it possible to show only pages with a predefined ID? Please advise if this is an option – it’s a great plugin otherwise!
Thanks
September 28, 2016 at 1:50 pm #10279Ernest MarcinkoKeymasterHi!
Thank you for your kind words!
Well, there is no option on the back-end to restrict to a certain set of pages – only excluding/including by certain categories or users (Advanced Options -> Exclude results panel), but since pages don’t have categories it won’t help.
I’ve looked up the code and I remembered that I have added a possibility to programatically restrict the results to a given set of IDs with a filter.
Try the following solution:
1. Make sure you have a back-up copy of your site just in case.
2. Try putting this custom code anywhere into functions.php file in your active theme directory:[php]add_filter(‘asp_query_args’, ‘asp_posts_only_in’, 1, 1);
function asp_posts_only_in($args) {
// Enter the page IDs here
$page_ids = array(1, 2, 3, 4, 5, 6);// Do not edit the code below
if ( count($page_ids) > 0 )
$args[‘post_in’] = $page_ids;return $args;
}[/php]3. Enter the page IDs to the $page_ids variable, and that’s it. The search will only return results from the given page IDs 🙂
In case you have multiple search instances
.. and you only want to apply the change to one of them, then use this modified version of the code:[php]add_filter(‘asp_query_args’, ‘asp_posts_only_in’, 1, 2);
function asp_posts_only_in($args, $id) {
// Enter the page IDs here
$page_ids = array(1, 2, 3, 4, 5, 6);
$search_id = 1; // change this to the search ID// Do not edit the code below
if ( $search_id != $id )
return $args;if ( count($page_ids) > 0 )
$args[‘post_in’] = $page_ids;return $args;
}[/php]In this case, make sure to change the $search_id variable as well.
-
AuthorPosts
- You must be logged in to reply to this topic.