29 posts
  • Has been a member for 3-4 years
Delpierooo says

Hello.

Have a question and hope someone can help me. I have a filter added to my wordpress menu. Is there a way to get the page id for each menu item inside this filter? Is this possible? If yes, I would be very pleased if someone can help me out with this.

Tnx.

2822 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Is it just $item->ID ? Paste in a copy of the filter code if you can.

29 posts
  • Has been a member for 3-4 years
Delpierooo says

Hi,

that simply isn’t going ok, since I dont have the item or am missing something.

Menu filter:

add_filter( 'wp_nav_menu_items', 'custom_menu_function', 10, 2 );

Then the filter functions starts like this:

 function custom_menu_function ( $items, $args ) {

 $dom = new DOMDocument();
        $dom->loadHTML($items);
        $linkNodes = $dom->getElementsByTagName('a');
        $classes= $dom->getElementsByTagName('li');
        $count = $linkNodes->length;

        for($i = 0;$i < $count;$i++)
        {

How to get the page id's here for each menu item, not the id that the menu item has.
  }
}  

So if I have created page Test that has id=2 and I have tbhis item in the menu. How to get it’s id(2) in the menu filter above?

Am I missing some basic thing?

Tnx.

by
by
by
by
by
by