Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

4 Answers 4

There's a plugin for that :-)

http://wordpress.org/extend/plugins/hide-categories/

share|improve this answer
1  
I'm against using plugin for minor tasks like this. Plus you learn a thing or two looking at an actual code :) –  Sandro Dzneladze Oct 20 '11 at 12:17
    
plugin doesn't work –  Sandro Dzneladze Mar 15 '12 at 14:55

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.org/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);
    }
}
share|improve this answer
    
Your function will exclude posts of selected categories from the loop on the main blog listing page, from category listing pages and from archives very well, but not from Recent Posts and not from Recent Comments widgets in sidebar. How to resolve this? –  Iurie Feb 25 at 19:42
    
@lurie It is probably best to ask this as a separate question. –  helgatheviking Feb 25 at 21:41
    
OK, thank you! Here is my question: wordpress.stackexchange.com/q/136017/25187. –  Iurie Feb 26 at 13:57
    
Per @TheDeadMedic's answer I have revised this to work on all queries: wordpress.stackexchange.com/a/136023/6477 –  helgatheviking Feb 26 at 16:22

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

share|improve this answer
    
it didn't work :( –  Sandro Dzneladze Oct 20 '11 at 15:46

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.