Limit search function to a POD
-
Hello! I am new and hope to have found the correct place to ask!
I have found this code snippet which should limit the search function to Post and Pages:<?php function searchfilter($query) { if ($query->is_search && !is_admin() ) { $query->set('post_type',array('post','page')); } return $query; } add_filter('pre_get_posts','searchfilter'); ?>
The author states:
Notice the line that says
$query->set('post_type',array('post','page'));
You can filter the search results by changing the values in the array variable. Right now it is set to display posts and pages but you can modify it to display anything you want.
How can I modify this code to search in a POD named «pod_a»?
Obviously I should add the POD’s name in the array. But what would the correct syntax be?I also need to extend the code snippet to search in pod_a, pod_b or pod_c based on the user’s capabilities. Users having the role name user_a should only search in pod_a and so forth.
What would be the php code to grab the user’s role name, test it and perform a search in the correct POD?
Hope this is within the scope of your support service!
Kind regards,
Gunnar Grotnes
- The topic ‘Limit search function to a POD’ is closed to new replies.