Skip to main content
Simplified title and content. Indented code.
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

trying to get Get page id'sIDs from nav items

I am trying to get all the id'sIDs in my WordPress navigation and convert it to a string so that I can use it in my wp_querywith wp_query to get the pages that are only listed in the nav. Here is how I am getting my id'sThe code to get the IDs:

$menu_name = 'primary';

 if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] )) {
   {
 $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    $menu_items = wp_get_nav_menu_items($menu->term_id);
 }

 foreach ( $menu_items as $menu_item ) {
    $numbers[] = $menu_item->ID;
}

 $number = implode(',',$numbers);

What I am finding is that the codeBut it is returning the wrong numbers. When I go to the admin area and hover my mouse over the pages, the number that shows up in the address bar on the bottom of the screen doesn't match. What am I doing wrong?

trying to get page id's from nav items

I am trying to get all the id's in my WordPress navigation and convert it to a string so that I can use it in my wp_query to get the pages that are only listed in the nav. Here is how I am getting my id's

$menu_name = 'primary';

 if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ))    {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
 }

 foreach ( $menu_items as $menu_item ) {
 $numbers[] = $menu_item->ID;
}

 $number = implode(',',$numbers);

What I am finding is that the code is returning the wrong numbers. When I go to the admin area and hover my mouse over the pages, the number that shows up in the address bar on the bottom of the screen doesn't match. What am I doing wrong?

Get page IDs from nav items

I am trying to get all the IDs in my navigation and convert it to a string so that I can use it with wp_query to get the pages that are only listed in the nav. The code to get the IDs:

$menu_name = 'primary';

if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] )) {
    $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    $menu_items = wp_get_nav_menu_items($menu->term_id);
}

foreach ( $menu_items as $menu_item ) {
    $numbers[] = $menu_item->ID;
}

$number = implode(',',$numbers);

But it is returning the wrong numbers. When I go to the admin area and hover my mouse over the pages, the number that shows up in the address bar on the bottom of the screen doesn't match. What am I doing wrong?

Tweeted twitter.com/#!/StackWordPress/status/320489620200624128
edited title
Link
Jamie
  • 1.4k
  • 5
  • 25
  • 47

trying to convert wordpressget page id's from nav to stringitems

Source Link
Jamie
  • 1.4k
  • 5
  • 25
  • 47

trying to convert wordpress nav to string

I am trying to get all the id's in my WordPress navigation and convert it to a string so that I can use it in my wp_query to get the pages that are only listed in the nav. Here is how I am getting my id's

$menu_name = 'primary';

 if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ))    {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
 }

 foreach ( $menu_items as $menu_item ) {
 $numbers[] = $menu_item->ID;
}

 $number = implode(',',$numbers);

What I am finding is that the code is returning the wrong numbers. When I go to the admin area and hover my mouse over the pages, the number that shows up in the address bar on the bottom of the screen doesn't match. What am I doing wrong?