title: Filter wordpress search results depending on which user role is logged in
body: <p>I'm trying filter search results on my wordpress site, depending of which user role is currently logged in.</p>
  
  <p>I found various filters online which go in the functions.php, but I think i need to modify the function somewhat.</p>
  
  <p>My php skills are basic and this seems to break the site. I'm guessing the syntax is all wrong.</p>
  
  <p>Any pointers on where I'm going wrong? Thanks in advance!</p>
  
  <pre><code>// SEARCH FILTER
  function filter_search($query) {
      if (current_user_can('customer')) {
          if ($query-&gt;is_search) {
          $query-&gt;set('post_type', array('customers', 'images'));
          };
          return $query;
      } else {
          if ($query-&gt;is_search) {
          $query-&gt;set('post_type', array('journalists', 'images', 'videos', 'documents'));
          };
          return $query;
      };   
  };
  add_filter('pre_get_posts', 'filter_search');
  </code></pre>
  
  <p><br /></p>
  
  <p>I've created custom user roles, and 'customer' is one of them.</p>