I have a menu name Social Network
. I want to get the menus ID. I tried the following, but didn’t succeed.
global $wpdb;
$menu_slug = 'social-network';
$menu_id = $wpdb->get_results(
"
SELECT TERM_ID
FROM $wpdb->wp_terms
WHERE name = ".$menu_slug."
"
);
echo $menu_id;
You can use the function get_term_by and use ‘name’ in the field param.
Example:
Here is the link to the codex page:
http://codex.wordpress.org/Function_Reference/get_term_by
Hope this helps.
All you need is
get_terms()
Let’s write
wp_menu_id_by_name( $name )
Let’s use it
You don’t use the right code, use this instead:
I’ve used the
wp_get_nav_menu_object
. You can pass menu slug or name to it to get the menu object and then you can access theterm_id
from it. Codex for wp_get_nav_menu_object.