M
M
Muvka2018-05-04 18:03:13
WordPress
Muvka, 2018-05-04 18:03:13

How can I display a menu using WP_Query?

Hello, is it possible to access the menu, which is collected in the admin panel and displayed via wp_nav_menu(), with a query through WP_Query? Please provide an example request if possible.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Muvka, 2018-05-04
@Muvka

Looks like he figured it out. If you know the menu id, you can get an array of objects with

wp_get_nav_menu_items( 3, array( 'update_post_term_cache' => false ) )

It's like an example. The second argument for what is needed only, tell me, who knows. It's just that the site will have several menus with different markup. I like to be in complete control.

M
Max Medar, 2018-05-04
@MedVedar

What do you want to control there?
You can customize the menu however you want via walker . And for each menu, set your own walker.
An example of a walker for the bootstrap menu - https://github.com/wp-bootstrap/wp-bootstrap-navwalker
But no way through WP_Query. He needs someone else.
You can also pay attention to wp_get_nav_menu_object()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question