简体   繁体   中英

How can i get the list of Categories a specific Wordpress page is assigned to?

I can't seem to find an answer anywhere on the web to this, on posts i can do this, i'm sure there is a native Wordpress function for this. In Wordpress when your editing a "Page" and i mean a "Page" not a "Post", you can assign the page to one or more categories.

I would like to be able to get a list of the categories to which the page is signed to. I know i could ask the DATABASE directly but i'm sure there is native way to do this. After all it's allready implemented in the wordpress own editor.

Im looking for something like this:

$array = get_the_pages_categories($pageID);

Thanks!

Frist: wp dont have default category for page so you have to create custom taxonomy for page.

register_taxonomy( $taxonomy, $object_type, $args );

check this https://developer.wordpress.org/reference/functions/register_taxonomy/

Next: get that categoies list

$page_terms = get_the_terms( $page_id, $taxonomy );

check this https://developer.wordpress.org/reference/functions/get_the_terms/

i think it will be helpful for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM