Custom Fields
Re-Envisioned
Support General Edit _Post custom field combine 2 field and add to a field

  • Creator
    Topic
  • #10876
    justdoit123
    Participant

    Please help, in admin, I want to automatically combine 2 custom fields value into another custom field.

    But i don't know how to do this ?? Is this I have to place code to combine within function metabox ??

    thanks


    add_filter( 'rwmb_meta_boxes', 'test_register_meta_boxes' );

    function test_register_meta_boxes( $meta_boxes )
    {

    my code will goes here ?? ====

    }

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #10877
    justdoit123
    Participant

    How do i add code to combine combine 2 custom fields value into another custom fiel on submit _Post ?? thanks please help

    #10881
    Anh Tran
    Keymaster

    Hello,

    Can you please give me more details on combining two fields into one? Do you mean combining the values when saving?

    #10883
    justdoit123
    Participant

    yes, i mean combine the two fields into one (after check php if not)

    #10887
    justdoit123
    Participant

    also how do i add a js script to a metabox.io custom field in admin edit post ??? thanks

    #10892
    Anh Tran
    Keymaster

    Hi, to combine values of 2 fields when saving, please use this snippet:

    add_action( 'rwmb_after_save_post', function( $post_id ) {
        if ( isset( $_POST['field_1'] ) && isset( $_POST['field_2'] ) ) {
            $value = $_POST['field_1'] . $_POST['field_2'];
            update_post_meta( $post_id, 'field_combine', $value );
        }
    } );

    This snippet combines the values of field_1 and field_2 into field_combine.

    To add JS to a meta box, please use this snippet:

    add_action( 'rwmb_enqueue_scripts', function() {
        wp_enqueue_script( 'your-script', 'https://url-to-your-js-file', array( 'jquery' ), '', true );
    } ):
    #10896
    justdoit123
    Participant

    thank you for great support.
    BTW, how do i see list of action like this add_action( 'rwmb_after_save_post' ??

    One more question, I want to add a html div + small javascript directly to below a metabox custom field in admin, not in header load ??

    thanks

    #10898
    Anh Tran
    Keymaster

    List of actions are available in the documentation.

    To add small HTML and JS just below a field, you can use the after param of the field. See field settings for more details.

    #10899
    justdoit123
    Participant

    thank you very much, i will try

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Edit _Post custom field combine 2 field and add to a field’ is closed to new replies.