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'd like to add a checkbox to the category editor screen to allow the category to be "deactivated" (perhaps while the site owner works on the category content and posts). Once I've done this, what are my options for excluding the category's that are set to "inactive"?

One way I'm thinking I can do this is to just run a filter on wp_list_categories and in the exlude= list, I'd just insert a utility function that returns all cat_ids where inactive is checked true.

Are there other ways to do this?

share|improve this question
    
How many categories do you expect at most to be inactive? 10, 1000, 10k? –  MikeSchinkel Jan 23 '11 at 3:30
    
@Mike, I'd say, on average 5-10 –  Scott B Jan 24 '11 at 12:55
add comment

3 Answers

up vote 0 down vote accepted

Hi @Scott B:

If you are talking 5 or 10 categories then just save them as a comma-separated string of IDs in using update_option() and use it as you suggested with your wp_list_categories() 'exclude' argument. And this answer should show you how to add a field to the category screen:

share|improve this answer
add comment

I suggest you just make all your deactivated categories children of "deactivated" or something.

This way, you can just filter subcategories of "deactivated" in your wp_list_categories. Also, you won't need non-default database entries.

share|improve this answer
    
OK, iiuyc, just create a category named "inactive", then have the user place any category they won't to deactivate as a child of "inactive"? What if the user already has a category named "inactive"? –  Scott B Jan 24 '11 at 4:13
    
The suggested name was "deactivated". How about "deactivated_cats"? A user that has such a category already is probably writing his own script for a similar purpose, so it's unlikely he would need yours ^^ –  cbrandolino Jan 24 '11 at 5:09
add comment

WordPress by default does not offer anything to deactivate categories. You would then - as you already suggested in your question - need to subclass the query and remove the deactivated categories from anything ever queried category related. Good luck!

share|improve this answer
add comment

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.