It’s easy to get the type of the menu item.
Just call the setting’s value()
method, which in the case of a nav menu item, would return an array with items like type
(sample value: post_type
or taxonomy
) and object
(sample value: post
, page
or category
).
So in your case, just check whether the type
‘s value is taxonomy
.
$value = $setting->value();
$underlying_type = is_array( $value ) ? $value['type'] : '';
/* Sample dump output of the $value array:
Array
(
[menu_item_parent] => 0
[object_id] => 1
[object] => category
[type] => taxonomy
[type_label] => Category
[url] => https://example.com/category/uncategorized/
How to determine if WP_Customize_Nav_Menu_Item_Setting is a 'taxonomy' type? =>
[target] =>
[attr_title] =>
How to determine if WP_Customize_Nav_Menu_Item_Setting is a 'taxonomy' type? =>
[classes] =>
[xfn] =>
[position] => 3
[status] => publish
How to determine if WP_Customize_Nav_Menu_Item_Setting is a 'taxonomy' type? => Uncategorized
[nav_menu_term_id] => 89
[_invalid] =>
)
*/