How to get field settings
- This topic has 6 replies, 2 voices, and was last updated 5 years, 3 months ago by Alex. 
- 
		AuthorPosts
- 
		
			
				
July 13, 2020 at 9:13 AM #20743Alex ParticipantHi, 
 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.July 13, 2020 at 4:37 PM #20751Long Nguyen ModeratorHi 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. July 13, 2020 at 7:24 PM #20754Alex ParticipantHi 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');July 13, 2020 at 10:26 PM #20757Long Nguyen ModeratorHi 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. July 13, 2020 at 11:25 PM #20759Alex ParticipantI 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. July 14, 2020 at 9:24 AM #20762Long Nguyen ModeratorHi, I think there are two ways to achieve your goal: - Use the extension MB Settings Page, create some fields in a settings page, and get the field settings by using this code.
 $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/. - Just create a specific post and get the field settings from this post.
 Hope that helps. July 15, 2020 at 6:58 PM #20783Alex ParticipantThank you Long. That should work. 
- 
		AuthorPosts
- You must be logged in to reply to this topic.