I'm following the answer given for Add settings to menu items in the Customizer.
I'd like to inspect if a menu item is of type taxonomy
. However, get_post_type
returns nav_menu_item
. How do I dig deeper?
function customize_save_after($wp_customize)
{
foreach ( $wp_customize->settings() as $setting ) {
if ( $setting instanceof WP_Customize_Nav_Menu_Item_Setting ) {
$type = get_post_type($setting->post_id); // Returns 'nav_menu_item'.
// How to retrieve the underlying type?
$underlying_type = ....?
if ($underlying_type !== 'taxonomy')
{
return;
}
update_post_meta( $setting->post_id, '_my-custom-setting-field', (!empty( $setting->my_custom_setting_field) ) );
}
}
}