rwmb_set_meta in for Settings page field
Support › MB Settings Page › rwmb_set_meta in for Settings page fieldResolved
- This topic has 7 replies, 4 voices, and was last updated 3 years, 3 months ago by
Long Nguyen.
-
AuthorPosts
-
May 2, 2020 at 5:54 PM #19425
nolab
ParticipantHi!
And thanks in advance for your help.
I'm trying to update a input field of a settings page, when a user click on a button in the admin (wp_ajax_ hook function).
There I generate a json (it works) but I also want to update an input value with a value.
I don't know if I can call rwmb_set_meta in this wp_ajax_action, or if I am using the correct syntax because I'm getting a 500 error.
I have tried this:
rwmb_set_meta( 'generalsettings', 'idgeneratedcdn', 'value', array( 'object_type' => 'setting' ));and this
rwmb_set_meta( 'generalsettings', 'idgeneratedcdn', 'value');What am I doing wrong? the place I call the funcion or rwmb_set_meta for a settings page?
Thanks!!
May 4, 2020 at 9:28 AM #19436Long Nguyen
ModeratorHi,
The function
rwmb_set_meta()
will be included in the next release. At this time, please try to use the functionupdate_option()
to update the settings page option.Here is the sample code
add_action( 'init', function() { $settings_page = get_option( 'generalsettings' ); // the settings page ID $settings_page['idgeneratedcdn'] = 1000; // the field ID update_option( 'generalsettings', $settings_page ); // update } );
For more information, please follow the documentation https://developer.wordpress.org/reference/functions/update_option/
May 5, 2020 at 4:45 AM #19457nolab
ParticipantHi Long!!
Ok, good to know. Yes, I have done it as you suggest. Thanks!
And good to know that rwmb_set_meta will be available soon.
Best!!
November 3, 2021 at 8:40 PM #31716Wolfgang
ParticipantHi,
just found that thread here and I'm facing a similiar problem.I tried to use the
rwmb_set_meta()
function for updating a value in a setting page. Unfortunately that value doesn't get updated. Refering to your docs (Docs) i used the option_name as object_id.That's what my options-page looks like:
function wcmvw_settingsPage_register($settings_pages) { global $vendorNames; //$vendorNames = get_option( 'wcmvw_settings' )['wcmvw_settings_vendorName']; $settings_pages[] = [ 'id' => 'wcmvw_settings', 'option_name' => 'wcmvw_settings', 'menu_title' => __( 'Rechnungen', 'wcmvw' ), 'position' => 0, 'parent' => '', 'style' => 'no-boxes', 'columns' => 1, 'tabs' => [ 'wcmvw_settings_general' => 'Allgemeine Einstellungen', ], 'tab_style' => 'left', 'submit_button' => __( 'Änderungen speichern', 'wcmvw' ), 'message' => __( 'Änderungen wurden gespeichert!', 'wcmvw' ), 'icon_url' => 'dashicons-admin-generic', ]; // Add Tabs dynamically! foreach ($vendorNames as $vendor) { $settings_pages[0]['tabs'] += [ str_replace(" ", "_", $vendor) => $vendor]; } return $settings_pages; }
And that's what that specific kind of code looks like:
$settings_page = get_option('wcmvw_settings'); $settings_page[$vendorInOrder[$i] . '_wcmvw_invoiceNumberGeneral_field'] = $vendorNextInvoiceNumber+1; update_option('wcmvw_settings', $settings_page); //rwmb_set_meta( 'wcmvw_settings', $vendorInOrder[$i] . '_wcmvw_invoiceNumberGeneral_field' , 'test' );
I've commented it out since the "native" option as suggested from you works fine for now. But i would, of course, prefer to use
rwmb_set_meta
here.Any thoughts what I'm doing wrong?
Thanks in Advance!
Cheers!November 13, 2021 at 8:00 PM #31901Wolfgang
ParticipantHey there,
any news on that problem? Do you need any further information? Is it a bug or am I doing something wrong?TIA for your answer!
Cheers
WolfgangNovember 14, 2021 at 10:54 PM #31912Long Nguyen
ModeratorHi,
The helper function
rwmb_set_meta()
is not working with the settings page. I've informed the development team to fix this issue in the next update. For now, you can use the WordPress functionupdate_option()
to update the field value on the settings page.January 14, 2022 at 3:36 AM #33215[email protected]
ParticipantCan you tell me if this has been fixed yet. I have been trying to use the rwmb_set_meta() function and the values do not appear to be getting saved.
January 14, 2022 at 12:58 PM #33220Long Nguyen
ModeratorHi Dom,
It was fixed. You can try to use this sample code
add_action( 'init', function() { $option_name = 'my_option'; $field_id = 'my_field'; $value = 'My custom value'; rwmb_set_meta( $option_name, $field_id, $value, [ 'object_type' => 'setting' ] ); }, 99 );
Refer to the documentation https://docs.metabox.io/rwmb-set-meta/#examples
-
AuthorPosts
- You must be logged in to reply to this topic.