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 would like to exclude categories from the loop using the "name" instead of the "id", since the ID can change when using new databases. The name however will always be the same.

Is this possible?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can use List Category Posts (Disclaimer: I'm the author of List Category Posts) or you can code this yourself:

$category_id = get_cat_ID($category_name);

This way you can get the id and exclude it from the loop with the minus sign. Example:

get_posts(cat=-1);
share|improve this answer

No.

WordPress very forcefully converts input of that argument to integers and is it part of sub-query from tables that don't actually contain category names.

You might be able to construct your own analogue using posts_where filter to modify SQL... But I think if you don't need a lot of categories to exclude it would be way more practical to simply convert names to IDs before querying.

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.