0

We have a category called "Tech", and want to hide posts from a specific author on this page.

For example, John Smith's posts do not show in Tech category, or any category for that matter, even search.

How could I do this? I don't want to hide the author name, I want to completely hide all posts by author X from the search, category, taxonomy pages etc.

Thank you

  • How are you listing the categories currently? get_categories? get_terms? – Howdy_McGee Mar 19 '14 at 14:29
  • 2
    I've done it now, cant post answer yet though. Basically a function for "pre_get_posts" which goes if is_category: $query->set( 'author', '-author_id' ); – user48887 Mar 19 '14 at 14:37
0

A filter on pre_get_posts should do it.

function hide_author_wpse_138491($qry) {
  $exc = 123;
  if (
    !is_admin()
    && !is_singular()
  ) {
    $qry->set('author','-'.$exc);
  }
}
add_action('pre_get_posts','hide_author_wpse_138491');

This should exclude results from the author with ID = 123 on all front end pages except for "single" pages, which sound like what you are aiming for-- ie, to "completely hide all posts by author X from the search, category, taxonomy pages etc."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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