Excluding categories from author archive pages

Community Forums Forums General Discussion Excluding categories from author archive pages

This topic is: resolved

This topic contains 1 reply, has 1 voice, and was last updated by  antman 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #59060

    antman
    Participant
    Post count: 10

    What is the best way to exclude certain categories on all author archive pages? I have the following code for my “functions.php” file, but I’m stuck:

    [php]
    // Exclude categories from author archive pages
    function exclude_categories_from_author_archives() {
    if ( is_author() && in_category(array(72,74,75) ) ) {
    // do something??
    }
    }
    add_action(‘???’,’exclude_categories_from_author_archives’);
    [/php]

    Any ideas?

    #59070

    antman
    Participant
    Post count: 10

    After getting pointed in the right direction and doing a little research, this works:

    [php]
    // Exclude categories from author archive pages
    function exclude_categories_from_author_archives( $query ) {
    if( $query->is_main_query() && $query->is_author() ) {
    $query->set( ‘cat’, ‘-72,-74,-75′ );
    }
    }
    add_action( ‘pre_get_posts’, ‘exclude_categories_from_author_archives’ );
    [/php]

    Thank you, Jennifer B. & Bill Erickson! For great info on customizing the WordPress query, check out Bill’s post:

    http://www.billerickson.net/customize-the-wordpress-query/

    • This reply was modified 11 months ago by  antman.
    • This reply was modified 11 months ago by  antman.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.