35 posts
  • Has been part of the Envato Community for over 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.

3310 posts
  • Provided great contribution to our forums
  • Nominated Community Superstar of the month
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
+18 more
dtbaker Moderator says

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

35 posts
  • Has been part of the Envato Community for over 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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by