Support

Account

Home Forums ACF PRO Consecutive numbers

Unread

Consecutive numbers

  • Hi everyone,

    At the moment we’re working on a big website with CPT and ACF. We would really like a field that check’s the field of a previous posts and adds +1.

    For example: Our latests post has a field called itemnumber with 250. When we publish that post and create a new post, that post should have 251 in the field itemnumber.

    We got this PHP from James Stout (support ACF)

    <?php  
    function my_acf_load_value( $value, $post_id, $field ) {     
    //get the value of the field from the db     
    $field_val = get_field('field_name',$post_id);     
    $new_value = $field_val++;    
    $new_val = $value;    
    return $value; 
    }  
    // acf/load_value/name={$field_name} - filter for a specific value load based on it's field name 
    add_filter('acf/load_value/name=field_name', 'my_acf_load_value', 10, 3);  
    ?>

    But we’re not sure how to get this to work

    Any help would be really appreciated.

    Kind regards,
    Robin Peek

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.