Home Forums Add-ons Repeater Field Need repeater data on publishing (save_post only works only updating,not create)


Need repeater data on publishing (save_post only works only updating,not create)

  • I am a bit confused here:

    I have written a little snippet in my functions.php that refines the data of my custom post type into external files.

    using save_post, acf/save_post, transition_post_status all have the same problem in common:

    I create my post, the script fires off and receives all data including “standard” acf field types. But not repeater fields.

    When I press “Update” on this published post, the missing data from the repeater fields is being added to my dataset, so in theory my script is working just fine….the only problem is that I cannot get the repeater field data on publishing. As this project will be used by an end user it is not desirable to tell him to press publish and then update afterwards 🙂

    I have tried more approaches than I can remember, but sadly I am failing here.

    the hook I am currently using is:
    add_action( 'acf/save_post', 'my_function', 20 );

    I hope that there is someone out there who has a solution to this.

  • In case it helps, here is the code:

    Few explanations on what is trying to be achieved:
    • The user has a library of images that he uses to build comics. There are 2 repeater fields within one “comic” custom post type: “comic slides” (images within a comic) and “comic_bildkomposition” (layers of images within a slide that will be put into a final image)
    • current_timestamp is being used as an ID for each comic that is being built.
    • there are 2 repeater fields: “comic_slides” and nested in it there are the fields “comic_text” (wysiwyg field) and “comic_bildkomposition” (repeater field for the image layers within a slide)


    function lextoons_comic_builder( $ID ) {

    $comic_slides = get_field(‘comic_slides’);

    // $comic_excerpt = substr(get_field(‘comic_excerpt’), 0, 120);
    [Author comment: this was a test in order to see if the function receives acf custom field data at all, which it does, “comic_excerpt” is a custom description field that is being put into the variable and printed just fine

    $comic_timestamp = get_field (‘timestamp’);
    $current_timestamp = time();
    $timestamp_field_key = “field_53da164db054e”;
    $comic_title = get_the_title();

    //check if comic timestamp has been set yet for this post, set an ID based on timestamp if not
    if ($comic_timestamp < 1 ) {
    update_field( $timestamp_field_key, $current_timestamp, $ID );
    $comic_timestamp = $current_timestamp;
    $pathname = “”.$_SERVER[‘DOCUMENT_ROOT’].”wp-content/uploads/comics/”.$comic_timestamp.””;
    //print $pathname;

    //If an ID has been set before, delete all files in the folder of this comic for recreation afterwards
    if ($comic_timestamp > 1 ) {
    //echo “<br/>Files: <br/>”;
    foreach (glob(“”.$_SERVER[‘DOCUMENT_ROOT’].”wp-content/uploads/comics/”.$comic_timestamp.”/*.*”) as $filename) {
    // echo “$filename size ” . filesize($filename) . “<br/>”;

    //Now, Loop through all Comic Slides and Generate a single Image out of each slides’ Layer
    $slide_nr = 0;
    foreach ($comic_slides as $comic_slide) {
    $slide_text = $comic_slide[‘comic_text’];
    $slide_text = substr($slide_text, 3, -5);
    $comic_layers =$comic_slide[‘comic_bildkomposition’];

    $width = get_field (‘image_input_width’, ‘options’);
    $height = get_field (‘image_input_height’, ‘options’);
    $newwidth = get_field (‘image_output_width’, ‘options’);
    $newheight = get_field (‘image_output_height’, ‘options’);

    $image = imagecreatetruecolor($width, $height);

    foreach ($comic_layers as $layer) {
    unset ($layer_data);
    // to make background transparent
    imagealphablending($image, false);
    $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127);
    imagefill($image, 0, 0, $transparency);
    imagesavealpha($image, true);
    imagealphablending($image, true);
    $layer_url = $layer[‘comic_layer’][‘url’];
    print $layer_url;
    $layer_data = imagecreatefrompng($layer_url);
    imagecopy($image, $layer_data, 0, 0, 0, 0, $width, $height);
    imagealphablending($image, false);
    imagesavealpha($image, true);

    $image2 = imagecreatetruecolor($width, $height);
    $white = imagecolorallocate($image, 255, 255, 255);
    imagefill($image2, 0, 0, $white);
    imagecopy($image2, $image, 0, 0, 0, 0, $width, $height);

    //create a thumb file img for resizing
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresized($thumb, $image2, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    imagepng($thumb, “”.$_SERVER[‘DOCUMENT_ROOT’].”wp-content/uploads/comics/”.$comic_timestamp.”/”.$comic_title.”_”.$slide_nr.”.png”);
    unset ($image);
    unset ($image2);
    unset ($thumb);

    add_action( ‘acf/save_post’, ‘lextoons_comic_builder’, 20 );


Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Need repeater data on publishing (save_post only works only updating,not create)’ is closed to new replies.