Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Garconis/2020361b37b25d64a63b99cf5f0ec0b7 to your computer and use it in GitHub Desktop.
Save Garconis/2020361b37b25d64a63b99cf5f0ec0b7 to your computer and use it in GitHub Desktop.
WordPress | Remove post from main blog loop if it has a certain Tag
<?php
/**
* https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
* On the page that is set to be the blog homepage (Posts Page), exclude a post from the loop, if it has a certain tag ID
**/
// exclude posts from the main blog loop, if it has the Focus tag
function fs_exclude_specific_tag( $query ) {
if ( !is_admin() && $query->is_home() && $query->is_main_query() ) {
// $query->set( 'tag', '-141' );
$query->set( 'tag__not_in', array('141') );
}
}
add_action( 'pre_get_posts', 'fs_exclude_specific_tag' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment