• Hello i’ve been googling around and found this tutorial “Hide a certain Category’s Posts from the Home page in WordPress”

    //Exclude Category Posts from Home Page
    function themeprefix_exclude_category($query) {
    	if ( $query->is_home() ) {
    	$query->set('cat', '-338');//add your category number
    	}
    	return $query;
    }
    add_action('pre_get_posts', 'themeprefix_exclude_category');

    That however lets you exclude from the home page but what i wanted to accomplish is something a bit more complex.

    I want to exclude certain categories on all Category Pages except in some category pages. Confusing? Yes I know my explanation is a bit. Theorically the code could be something like

    if ( $query->is_not_category(1,2,3) ) { // if it's not the category pages where i DONT want to remove
    	$query->set('cat', '-338');//then remove this category ID from being shown.

    However i don’t really know a lot about programming. Any help? Not sure if there’s even a easier way. Just trying to find out

  • The topic ‘Hide a certain Category’s Posts from a certain Category page in WordPress’ is closed to new replies.