سؤال

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?

هل كانت مفيدة؟

المحلول

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);

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top