Support Forum
Hi,
Probably a silly question. I am trying to get options from a custom field type of Select using rwmb_get_field_settings(). The call is made with REST from front-end to the custom endpoint. Calling rwmb_get_field_settings() in the functions.php return false. Any ideas?
Thank you.
Hi Alex,
Did you pass the arguments to the function rwmb_get_field_settings( $field_id, $args, $object_id )
?
Please share the code that you create the field and get the field settings. I will take a closer look and give a quick response.
Hi Long,
Yes, I did use $field_id. It seems none of the helper functions work. I tried a few other with no success. The fields are visible in the Post. I can change the values.
Here is just part of the Metabox.
function.php
add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes');
function prefix_register_meta_boxes($meta_boxes) {
if (!class_exists('RW_Meta_Box')) {
return;
}
/*=================================================
* Properties Custom Type Metabox
===================================================*/
$meta_boxes[] = array(
'id' => 'property-meta-box',
'title' => esc_html__( 'Property', 'textdomain' ),
'pages' => array('property'),
'tabs' => array(
'property_location' => array(
'label' => esc_html__('Location', 'textdomain'),
'icon' => 'dashicons-location',
),
),
'tab_style' => 'left',
'fields' => array(
array (
'id' => 'country',
'name' => esc_html__( 'Country', 'textdomain' ),
'type' => 'select',
'placeholder' => esc_html__( 'Select an Item', 'textdomain' ),
'options' => array(
1 => esc_html__( 'Canada', 'textdomain' ),
2 => esc_html__( 'United States', 'textdomain' ),
),
'tab' => 'property_location',
'columns' => 12,
),
),
);
return $meta_boxes;
}
$field = rwmb_get_field_settings('country');
Hi Alex,
If you are using the helper function rwmb_get_field_settings()
outside the loop, you have to pass the argument $object_id
(post ID) to this function.
$field = rwmb_get_field_settings( 'country', '', 1234 );
For more information, please follow this documentation https://docs.metabox.io/rwmb-get-field-settings/#arguments.
I have front-end React app. I am using WordPress as headless CMS. The post doesn't exists yet. Hence I do not have post_id to pass it to the function. The idea is when a user opens form to create a new post, one of the fields is the Country select field. I was hoping to get options for this front-end field by fetching options from the custom Country back-end field. It is not a direct access. My app fires REST request to the custom endpoint. The custom endpoint function uses rwmb_get_field_seetings to get options and send it back to the from-end app. Is it even possible with Metabox? It did work with ACF.
Thanks.
Hi,
I think there are two ways to achieve your goal:
$field = rwmb_get_field_settings( $field_id, ['object_type' => 'setting'], $option_name );
Follow this documentation for more information https://docs.metabox.io/extensions/mb-settings-page/.
Hope that helps.
Thank you Long. That should work.