Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to get the post id by the navigation id to use in a loop. I made a new query to get posts. I am using multiple queries on a page because I need to. one of the queries gets page templates that have categories that you make a post to and it gets displayed by that template. My problem is that if I put in the query to get posts, then I end up with the data in the theme twice. So I want to make it so that only a post that has a navigation link will be displayed. It will still be able to link to the post but I only want the query to get a post that has a nav item. Every time I try, all I end up with is a bunch of this

 bool(true)

The functions I have read about, some from this site aren't working the way I understand they should. I have taken code straight out of the codex and it comes up empty http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items

                $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);
echo $menu_items->ID;

My attempts have returned nothing.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I think you need to loop the $menu_items because the function, according to the Codex, returns a array.

Remplace echo $menu_items->ID; with

 foreach ( $menu_items as $menu_item ) {
    echo $menu_item->ID;
 }

I need to check the array exactly, but if you need to compare a post ID to a menu item, you will need to compare $menu_item->object_id which contains the ID of the post the menu-item is linking to.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.