Support

Account

Home Forums ACF PRO Alternative to load_value that ONLY runs on save and saves data to database?

Unread

Alternative to load_value that ONLY runs on save and saves data to database?

  • I have this snippet which works and runs using load_value. However, load_value runs on the fly every time it is loaded. Therefore it interferes with my faceting plugin. It also just loads the data and doesn’t save it. So I have to update the post to load the data and update it again to save the data.

    What I need to do is for the code below to work and save the data every time a post is saved. And not before or after – to not work on the fly. Is that possible somehow maybe with a different filter? Or some extra code?

    function my_acf_set_repeater($value, $post_id, $field){
    $value = array();
    $dates = get_field(‘multiple_dates’);
    // below is repeater field key
    foreach( $dates as $date ){
    $value []= array(‘field_630f195c9942e’ => $date);
    }
    return $value;
    }
    //normal dates is the repeater name
    add_filter(‘acf/load_value/name=dates_repeater’, ‘my_acf_set_repeater’, 10, 3);

    I also tried:

    function my_acf_set_repeater($post_id){

    $value = array();
    $dates = get_field(‘multiple_dates’);

    // below is repeater field key
    foreach( $dates as $date ){
    $value []= array(‘field_630f195c9942e’ => $date);
    }

    return $value;
    }

    add_action(‘acf/save_post’, ‘my_acf_set_repeater’, 5);

    But I’m a noob so that didn’t work. But I can’t be asking for something too difficult?!

    Thank you

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.