Created
September 23, 2017 21:32
-
-
Save metinsaylan/e4d233018ca7eaaf604c7124710e2d9d to your computer and use it in GitHub Desktop.
Exclude terms from your tag and category widgets http://metinsaylan.com/wordpress/2011/06/12/how-to-exclude-categories-and-tags-from-your-widgets/
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 | |
function shailan_filter_terms( $exclusions, $args ){ | |
// IDs of terms to be excluded | |
$exclude = "3,257"; // CHANGE THIS TO IDs OF YOUR TERMS | |
// Generation of exclusion SQL code | |
$exterms = wp_parse_id_list( $exclude ); | |
foreach ( $exterms as $exterm ) { | |
if ( empty($exclusions) ) | |
$exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; | |
else | |
$exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; | |
} | |
// Closing bracket | |
if ( !empty($exclusions) ) | |
$exclusions .= ')'; | |
// Return our SQL statement | |
return $exclusions; | |
} | |
// Finally hook up our filter | |
add_filter( 'list_terms_exclusions', 'shailan_filter_terms', 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment