douruanfan3030 2017-01-25 04:21
浏览 55
已采纳

如何获取特定Wordpress页面分配的类别列表?

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!

  • 写回答

1条回答 默认 最新

  • dongmu5596 2017-01-25 05:07
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部