• Resolved Redouane

    (@donlk)


    Hi,

    I’m wondering if it’s possible to edit the query of the author pages to exclude a certain category or two. for example, if I want all author pages to only show their posts in “op-ed” category but not “news”, how would I go about that?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Use the “pre_get_posts” action to alter the query. You can set any query var used in WP_Query. For example, the category arguments. For many of these, you need the term ID. You can get this by going to the Categories admin screen and following the Edit action link for a term. Look at the URL in your browser’s address field, the term ID is the number after tag_ID= in the URL parameters.

    In the action callback, before setting any query vars, use is_main_query() and is_author() to be sure you only adjust the correct queries, since nearly all post queries go through this action.

    Thread Starter Redouane

    (@donlk)

    much appreciated on the help, I’ve used your suggestions paired with category__not_in to achieve the desired results.

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Author pages: exclude articles from certain categories’ is closed to new replies.