rwmb_set_meta in for Settings page field

Support MB Settings Page rwmb_set_meta in for Settings page fieldResolved

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #19425
    nolabnolab
    Participant

    Hi!

    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!!

    #19436
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The function rwmb_set_meta() will be included in the next release. At this time, please try to use the function update_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/

    #19457
    nolabnolab
    Participant

    Hi 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!!

    #31716
    WolfgangWolfgang
    Participant

    Hi,
    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!

    #31901
    WolfgangWolfgang
    Participant

    Hey 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
    Wolfgang

    #31912
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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 function update_option() to update the field value on the settings page.

    #33215
    dom@viewtolearn.co.uk[email protected]
    Participant

    Can 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.

    #33220
    Long NguyenLong Nguyen
    Moderator

    Hi 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

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.