doujianmin6527 2014-02-19 21:33
浏览 50
已采纳

Wordpress WP_Post对象ID与管理区域中的页面ID不匹配

I'm getting a menu in wordpress using this code

$items = wp_get_nav_menu_items( 'Top menu', $args );

It returns an array with items such as below

[4] => WP_Post Object
            (
                [ID] => 54
                [post_author] => 1
                [post_date] => 2014-02-19 20:36:53
                [post_date_gmt] => 2014-02-19 20:36:53
                [post_content] =>  
                [post_title] => 
                [post_excerpt] => 
                [post_status] => publish
                [comment_status] => open
                [ping_status] => open
                [post_password] => 
                [post_name] => 54
                [to_ping] => 
                [pinged] => 
                [post_modified] => 2014-02-19 20:36:53
                [post_modified_gmt] => 2014-02-19 20:36:53
                [post_content_filtered] => 
                [post_parent] => 7
                [guid] => http://localhost:8888/eastleigh/?p=54
                [menu_order] => 6
                [post_type] => nav_menu_item
                [post_mime_type] => 
                [comment_count] => 0
                [filter] => raw
                [db_id] => 54
                [menu_item_parent] => 27
                [object_id] => 46
                [object] => page
                [type] => post_type
                [type_label] => Page
                [url] => http://localhost:8888/eastleigh/about/menus/
                [title] => Menus
                [target] => 
                [attr_title] => 
                [description] => 
                [classes] => Array
                    (
                        [0] => 
                    )

                [xfn] => 
            )

Seems fine, but when i go into wordpress the page doesn't have that ID , in fact no pages do ( i hovered of the pages in the admin to check the page_id). It does however match the object_id (46)

if i dump out the get_pages array then the same page has the current id (46)

[5] => WP_Post Object
    (
        [ID] => 46
        [post_author] => 1
        [post_date] => 2014-02-19 20:35:25
        [post_date_gmt] => 2014-02-19 20:35:25
        [post_content] => 
        [post_title] => Menus
        [post_excerpt] => 
        [post_status] => publish
        [comment_status] => open
        [ping_status] => open
        [post_password] => 
        [post_name] => menus
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2014-02-19 20:35:25
        [post_modified_gmt] => 2014-02-19 20:35:25
        [post_content_filtered] => 
        [post_parent] => 7
        [guid] => http://localhost:8888/eastleigh/?page_id=46
        [menu_order] => 0
        [post_type] => page
        [post_mime_type] => 
        [comment_count] => 0
        [filter] => raw
    )

Could someone please explain what i'm missing here?

Thank you

  • 写回答

2条回答 默认 最新

  • dongting3135 2014-02-19 21:41
    关注

    A nav menu item ID isn't the same as a post (page) ID. The comparable ID you're looking for is the object_id which you've already pointed out is the same.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误