wordpress theme: How to get term data in archive——get_queried_object()
I've been iterating my own wordpress theme recently.
It is very common to obtain the term data of category and post-tag, two existing WordPress taxonomies, in the archive, and both have ready-made parameters and functions.
How to get the term data of custom taxonomy in archive?
get_queried_object()
This function can not only obtain the term data of custom taxonomy, but also the data of category and post-tag. Even if it is an archive of a custom post type, you can also get the current post type data.
$term_data = get_queried_object();//In archive.php, use it directly.
URL on wordpress official website: https://developer.wordpress.org/reference/functions/get_queried_object/
You can also get the current post and user data. However, I haven't tried these two.