Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to restrict search results to only those posted by the logged in user? I have a front-end form the user fills out.

Every user has a front-end dashboard and is able edit their own post. Since they may have many posts I would like them to be able to search for their own posts, but not display posts from other authors (this would only complicate things) Is there a way to do this?

share|improve this question

1 Answer 1

Something like this should work:

function my_search_filter($query){
  if($query->is_search)
    $query->set('author', get_current_user_id());

  return $query;
};

add_filter('pre_get_posts', 'my_search_filter');
share|improve this answer
    
thank you for the info, not sure how to implement it though. I placed it in the functions.php - but I'm still able to search for other author's posts. –  user7481 Sep 7 '11 at 19:37
    
Doesnt it work as intended? –  p.a. Sep 13 '12 at 10:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.