Skip to content

Instantly share code, notes, and snippets.

@aldolat
Last active December 3, 2016 09:13
Show Gist options
  • Select an option

  • Save aldolat/1b32333bc003bc6586b0bafcf4dd2afd to your computer and use it in GitHub Desktop.

Select an option

Save aldolat/1b32333bc003bc6586b0bafcf4dd2afd to your computer and use it in GitHub Desktop.
Hide posts from a certain category in the main query.
<?php
/**
* Change the main query in order to hide posts from certain categories.
*
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function my_customized_query( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-10,-11,-325' );
}
}
add_action( 'pre_get_posts', 'my_customized_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment