Support

Account

Forum Replies Created

  • Apparently this is not supposed to be done like this, or I’m just stupid 😀

    I ended up sending the data along with my already sent custom JSON for my custom post type like this:

    
    // Add ACF data to our update request, if available.
    var acf_form = $('.has_acf #acf-form');
    if(acf_form) {
      // Serialize data in acf form.
      var acf_data = $(acf_form).serializeArray();
      // Apply every field to the data object, we're sending.
      for(var i = 0; i < acf_data.length; i++) {
        var field = acf_data[i];
        data[field.name] = field.value;
      }
    }
    

    Originally, I wanted to avoid doing anything more complicated on the PHP side, but it turned out to be quite easy. I added the following statements to the new and update ajax methods:

    
    // Update ACF Fields
    if( function_exists( 'update_field' ) && isset( $_POST['acf'] ) ) {
      foreach( $_POST['acf'] as $field_name => $field_value ) {
        update_field( $field_name, esc_attr( $field_value ), $post_id );
      }
    }
    

    It seems to work fine 🙂 (I just want basic support, didn’t test repeaters and more complicated fields.)

Viewing 1 post (of 1 total)