Custom Fields
Re-Envisioned
Support General Update content(date) in FIELD_B when FIELD_A is saved with changes

  • Creator
    Topic
  • #32006
    Kyle B.
    Participant

    Basically, I am trying to update the date in "Tax Rates Updated" any time the "Tax Rates" field is changed and saved. I have managed to catch when the Tax Rates field has been changed but I do not know how to change the date inside of the "Tax Rates Updated" field of the post.

    The post: https://i.imgur.com/THKXVoo.png

    The code(so far): https://i.imgur.com/uW4P15V.png

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

    Hi Kyle,

    You can use the helper function rwmb_set_meta() to set the value for a field. Or use the WordPress function update_post_meta(). Please read more on the documentation
    https://docs.metabox.io/rwmb-set-meta/
    https://developer.wordpress.org/reference/functions/update_post_meta/

    #32016
    Kyle B.
    Participant

    Not sure what I am missing here, the field is not updating.

    <?php
    add_action( 'rwmb_district_tax_rate_after_save_field', function ( $null, $field, $post_id, $old, $new ) {
        rwmb_set_meta( $post_id, 'district_proposed_rate', $new );
    }, 10, 5 );

    View post on imgur.com

    #32024
    Long Nguyen
    Moderator

    Hi,

    Please pass the parameters to the helper function in the correct order.

    add_action( 'rwmb_district_tax_rate_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
        rwmb_set_meta( $object_id, 'district_proposed_rate', $new );
    }, 10, 5 );

    and the field district_proposed_rate should be a text field.

    #32026
    Kyle B.
    Participant

    It is not updating other fields. It only works if I am checking FIELD_A and updating FIELD_A. If I check FIELD_A and try to update FIELD_B it does not work. Here is a video: https://www.loom.com/share/dda428cc81074d5fa225a6ac98063230

    #32037
    Long Nguyen
    Moderator

    Hi,

    I got the issue. It does not work on your site because the field text_to_input is registered and saved first. If you want to update the field text_to_update, please drag and drop it above the field text_to_input. Like this https://share.getcloudapp.com/d5u6JvQz

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