I'm currently trying to delete metakeys once my plugin is uninstalled to keep the database clean.
My code is as follows:
Array of meta_keys
that are created
$keys = array (
'_menu_item_icon',
'_menu_item_hide',
'_menu_item_block',
'_menu_item_center',
}
// Menu items.
$menu_items = get_posts( array(
'post_type' => 'nav_menu_item',
'numberposts' => -1,
'nopaging' => true,
'fields' => 'ids'
) );
if ( $menu_items ) {
foreach ( $menu_items as $post_id ) {
wp_delete_post( (int) post_id, true );
}
}
Was hoping to use an array ('meta_key' => $keys
) for the meta_key and iterate through each but that doesn’t seem to work. Is there a better approach?