Login

wordpress theme: How to get term data in archive——get_queried_object()

Author:neo yang Time:2023/05/16 Read: 7379

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.

tags:


copyright © www.lyustu.com all rights reserved.
Theme: TheMoon V3.0. Author:neo yang