WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Something like this should work:

function my_search_filter($query){
    $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


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.