Tet banner

Custom Fields
Re-Envisioned
Support General std value not working for Numeric field

  • Creator
    Topic
  • #30429
    closemarketing
    Participant

    Hello,
    I'm trying to use a default value but in numeric field is not working. std is supposed to work, but not.
    How could use a default value?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #30435
    Long Nguyen
    Moderator

    Hi,

    I didn't see any issue with the setting std of the field number.

    'fields' => [
        [
            'name' => __( 'Number', 'your-text-domain' ),
            'id'   => $prefix . 'number_meta',
            'type' => 'number',
            'std'  => 123,
        ],
    ],

    Can you please share the code that creates the fields? And follow the Debugging Information step to troubleshoot the issue https://metabox.io/support/topic/how-to-create-a-new-topic/

    #32086

    Hi Long,
    I decided to ask here so I won't be opening another thread...
    The standard value for a number field doens't work for me either, I set to 0 but is empty when I create a new post...
    Any clue?

    Angelo

    #32090
    Long Nguyen
    Moderator

    Hi Angelo,

    Please share the code that creates the number field and a screen record on your site after you deactivate all plugins except Meta Box and switch to the standard theme of WordPress.

    #32091

    Hi Long,
    I tried to deactivate all plugins except Oxygen,Metabox and Metabox AIO, no luck...
    Although I use the visual version of metabox, If I go to "Generate PHP" to grab the code the result is as follows:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
    $meta_boxes[] = [
        'title'      => __( 'Prezzo vendita', 'your-text-domain' ),
        'id'         => 'prezzo-vendita',
        'post_types' => ['vendita'],
        'fields'     => [
            [
                'name'          => __( 'VALORE VENDITA', 'your-text-domain' ),
                'id'            => $prefix . 'valore_vendita',
                'type'          => 'number',
                'step'          => 'any',
                'required'      => true,
                'admin_columns' => 'after Title',
            ],
        ],
    ];
    return $meta_boxes;
    }

    It is a development site, if you want the credentials pls let me know

    #32099
    Long Nguyen
    Moderator

    Hi Angelo,

    As you can see on your code, there is no setting std of the number field.

    [
        'name' => __( 'Number', 'your-text-domain' ),
        'id'   => $prefix . 'number_4mgm8pyvpnu',
        'type' => 'number',
        'std'  => 111,
    ],

    In the builder, you can add the default value to the option "Default value", screen record https://share.getcloudapp.com/Jrun5n5g

    #32101

    Sorry, I forgot to mention that It Is set in the settings.....I did set it to zero...that Is the problem
    ...

    #32111
    Long Nguyen
    Moderator

    Hi,

    Thanks, I see that. Please use the code instead of the builder. I will inform the development team to support this case in future updates.

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