#22867 closed defect (bug) (worksforme)
Function wp_get_nav_menu_items - Fatal error - Wordpress 3.5 and earlier
Reported by: | sporky | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3 |
Component: | Menus | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description (last modified by )
The function wp_get_nav_menu_items fails when a "Page" type post has been added to a menu.
This is a fresh install of Wordpress 3.5, using the "Sample Page" page added to a menu called "main_menu". This menu has no other menu options added to it. This bug also occurs in earlier versions of Wordpress.
Sample PHP Code:
<?php $menu_name = 'main_menu'; $nav_menu_object = wp_get_nav_menu_object($menu_name); $menu_id = $nav_menu_object->term_id; $menu_items = wp_get_nav_menu_items($menu_id); <<--- Error occurs here ?>
The following error occurs:
Fatal error: Call to a member function get_page_permastruct() on a non-object in C:\xampp\htdocs\lchs4\wp-includes\link-template.php on line 271
This occurs in the following area of code:
function _get_page_link( $post = false, $leavename = false, $sample = false ) { global $wp_rewrite; $post = get_post( $post ); $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); $link = $wp_rewrite->get_page_permastruct(); <--- happens here
Essentially, the variable $wp_rewrite shows as <Uninitialized> when viewed in xdebug using Eclipse.
Change History (6)
Note: See
TracTickets for help on using
tickets.
$wp_rewrite
is set after plugins are loaded.You're probably calling
wp_get_nav_menu_items()
too early. That code needs to wait at least until theinit
action runs.