I want to get rid of some posts, old ones, that I don't really want to keep. I was thinking to create a category named 'old' and use it as a garbage can to trash everything I don't like from old posts.
Reason I don't simply delete them is the google traffic. Some of those pages receive 1-2 visits a day, so why not leave them? just as adsense traffic :)
Anyhow.
Now I need a way to hide category 'old' from everywhere. I need a quick and dirty way to do this, preferably through functions.php - don't want to change every menu listing and add -old.
I also want to exclude posts inside this category from being displayed in 'related posts' section. But for this I guess I will have to take a look in the plugin itself...
any help?
Thanks!
I want to get rid of some posts, old ones, that I don't really want to keep. I was thinking to create a category named 'old' and use it as a garbage can to trash everything I don't like from old posts.
Reason I don't simply delete them is the google traffic. Some of those pages receive 1-2 visits a day, so why not leave them? just as adsense traffic :)
Anyhow.
Now I need a way to hide category 'old' from everywhere. I need a quick and dirty way to do this, preferably through functions.php - don't want to change every menu listing and add -old.
I also want to exclude posts inside this category from being displayed in 'related posts' section. But for this I guess I will have to take a look in the plugin itself...
any help?
Thanks!
pre_get_posts
is the right hook for this
since i just did category exclusion in another answer i will post it here too. Exclude the category from the WordPress loop
based on the codex sample:
http://codex.wordpress/Custom_Queries#Category_Exclusion
add_action('pre_get_posts', 'wpa_31553' );
function wpa_31553( $wp_query ) {
//$wp_query is passed by reference. we don't need to return anything. whatever changes made inside this function will automatically effect the global variable
$excluded = array(272); //made it an array in case you need to exclude more than one
// only exclude on the front end
if( !is_admin() ) {
$wp_query->set('category__not_in', $excluded);
}
}
There's a plugin for that :-)
http://wordpress/extend/plugins/hide-categories/
can you try this, add in your function.php
add_action('pre_get_posts', 'block_category' );
function block_category() {
global $wp_query;
$wp_query->query_vars['cat'] = '-1';
}
replace -1 with your cat id
can you try again with a conditional tag
function exclude_category($query) {
if ( $query->is_home ) {
$query->set('cat', '-xx');
}
return $query;
}
xx is your category