Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
share|improve this question
    
What exactly is inside $args? –  kaiser Jun 26 '13 at 9:38
add comment

1 Answer

You don't use the right code, use this instead:

global $wpdb;

$tablename = $wpdb->prefix.'terms'; // use always table prefix
$menu_name = 'top-menu'; // menu name
$menu_id = $wpdb->get_results(
    "
    SELECT term_id
    FROM ".$tablename." 
    WHERE name= '".$menu_name."'
    "
);

// results in array 
foreach($menu_id as $menu):
    echo $menu->term_id;
endforeach; 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.