Home Forums ACF PRO Prepopulate field


Prepopulate field

  • Hello,

    I am trying to pre populate a field with the value of the same field taken from the last post + 1

    So lets say that the last CPT has field ‘number’ = 10.
    I would like when adding a new CPT to pre populate the ‘number’ with value 11.
    This is the code i use:

    add_filter('acf/load_field/name=number', 'my_acf_default_bill');
    function my_acf_default_bill($field) {
        $latest_bill = get_posts("post_type=bills&numberposts=1");
        $new_bill = get_field( 'number', $latest_bill[0]->ID );
        $field['default_value'] = ++$new_bill;
        return $field;
Viewing 1 post (of 1 total)

The topic ‘Prepopulate field’ is closed to new replies.