Further to this I have this code that shows the select list in my product CPT but the list is empty:
add_filter( 'rwmb_meta_boxes', 'register_custom_meta_boxes' ); // Hook into Meta Box to register custom meta boxes
function register_custom_meta_boxes( $meta_boxes ) {
// Retrieve stored values from the settings page field
$options = get_option( 'prod_cats_test', [] ); // Replace with the actual field key inside your settings page
// Ensure values are correctly formatted before populating the select field
if ( is_array( $options ) && !empty( $options ) ) {
$formatted_options = array_combine( $options, $options ); // Convert array into key-value pairs for the select field
} else {
$formatted_options = []; // Fallback to an empty array to prevent errors
}
// Define the custom meta box for the specific post type
$meta_boxes[] = [
'title' => 'Product Categories', // Title of the meta box
'id' => 'custom_select_meta_box', // Unique ID for the meta box
'post_types' => ['product'], // Specify the post type(s) where this meta box should appear
'fields' => [
[
'id' => 'product_cats', // Field ID for storing the selection
'name' => 'Select an Option', // Label for the select field
'type' => 'select', // Define the field type as a dropdown select box
'options' => $formatted_options, // Populate dropdown dynamically
],
],
];
return $meta_boxes; // Return the modified array of meta boxes for registration
}