Created
June 27, 2018 20:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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