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.
<?php get_term_by( $field, $value, $taxonomy, $output, $filter ) ?>
Example:
$term = get_term_by('name', 'Social Network', 'nav_menu');
$menu_id = $term->term_id;
Here is the link to the codex page:
http://codex.wordpress.org/Function_Reference/get_term_by
Hope this helps.