Including only current user’s posts in search

After further testing, the problem was found to be caused by another filter, posts_where, which was registered to support searching also in custom fields, and that’s why only searching is affected.

Originally it generates something like this, so if the OR statement returns true (when one of the custom fields includes foo), that post will appear on the result page:

AND wp_posts.post_author IN (2) AND (
    (
        (wp_posts.post_title LIKE '%foo%') OR (wp_posts.post_content LIKE '%foo%')
    )
) AND ( /* wordpress stuff... */ ) OR ( /* section the filter generates... */ )

I have modified so that this filter returns:

AND wp_posts.post_author IN (2) AND (
    (
        (wp_posts.post_title LIKE '%foo%') OR (wp_posts.post_content LIKE '%foo%')
        OR ( /* section the filter generates... */ )
    )
) AND ( /* wordpress stuff */ )

Thanks to Johannes for giving me ideas that the original code should work 🙂