• My question is pretty straight forward but I am really hung up on this one. I have read the Codex for Pre_Get_Posts and I believe I am doing this correctly but it’s just not working.

    I have a custom post type in the theme I am using called Portfolio. The categories it uses are called project-categories. I am trying to make it to where anyone logged in cannot see a specific category. Here is my code so far

    function exclude_category( $query ) {
    if ( is_user_logged_in() && $query->is_main_query() ) {
    $taxquery = array(
    'post-type'=> 'portfolio',
    'taxonomy' => 'project-type',
    'field' => 'id',
    'terms' => array( 94 ),
    'operator' => 'NOT IN'
    );
    
    $query->set( 'tax_query', $taxquery);
    }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    Any help on this would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Having trouble with Pre_Get_Posts’ is closed to new replies.