How to manipulate data after submission?

Support MB Frontend Submission How to manipulate data after submission?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36872
    Amy SchmidtAmy Schmidt
    Participant

    For the frontend form, I am trying to set the fields of the 'date' to today when they submit. This is my code:

    
    add_action( 'rwmb_frontend_after_save_post', function( $object_post ) {
      global $wpdb;
    
      $postID = $object_post->post_id;
      
      $tz = 'America/Los_Angeles';
      $timestamp = time();
      try {
          $dt = new DateTime("now", new DateTimeZone($tz));
          $dt->setTimestamp($timestamp);
          $wpdb->query($wpdb->prepare("UPDATE wp_provider_units SET available='" . $dt->format('Y-m-d') . "' WHERE ID=".  $postID . " AND (available IS NULL OR available = '' OR DATE(available) < CURRENT_DATE());"));
      } catch (Exception $e) {
      }
    
    } );
    

    All that does is set the date for wp_provider_units but apparently, the frontend form actually pulls values from postmeta table. I have no idea why that table is even being used with custom tables being active, but it is and even with that hook it does not update postmeta with the proper values.

    I will note, this is a clone field, so I am trying to save the new date for all units with that post_id. Inside the postmeta table, it's serialized data that includes the entire array of the clone so I have no clue how to update just one field from that.

    Basically, all I really need to do is overwrite the date field with today's date for each clone. I don't care if it's done via SQL or through the metabox method but any help is greatly appreciated. Thanks

    #36884
    Long NguyenLong Nguyen
    Moderator

    Hi Amy,

    To update the field value in a custom table (created by Meta Box), you can follow this documentation to use the public API https://docs.metabox.io/extensions/mb-custom-table/#update

    If it does not work, please share the code that create the custom fields on your site, I can help you to check the issue.

    #36920
    Amy SchmidtAmy Schmidt
    Participant

    Thank you. I'll be working on it this week and I'll let you know!

    The person who coded this site before me hardcoded all these changes in the core metabox files so I'm looking to convert them to hooks so they don't disappear every update 🙂

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