douruanfan3030 2017-01-25 12: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 13: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.

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

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?