WordPress – how do I know if a menu item has children?
\wp-includes\nav-menu-template.php
function start_el(&$output, $item, $depth=0, $args=array()) {
global $wpdb;
$children_count = $wpdb->get_var(
$wpdb->prepare("
SELECT COUNT(*) FROM $wpdb->postmeta
WHERE meta_key = %s
AND meta_value = %d
", '_menu_item_menu_item_parent', $item->ID)
);
if( $children_count > 0 ) {
// has children
$classes[] = 'parent';
}
[...]