1

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?

2
  • How many categories do you expect at most to be inactive? 10, 1000, 10k? Commented Jan 23, 2011 at 3:30
  • @Mike, I'd say, on average 5-10
    – Scott B
    Commented Jan 24, 2011 at 12:55

3 Answers 3

0

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:

1

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.

2
  • 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
    Commented Jan 24, 2011 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 ^^ Commented Jan 24, 2011 at 5:09
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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