## How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?

Question

I’m using a function that changes the front-end and back-end post title for a custom post type according to what you put in certain custom fields.

    //Save ACF fields as post_content for back-end

function change_title_cars($post_id) { global$_POST;
if('cars'== get_post_type()){

$car_name = get_post_meta($post_id,'car_name',true);
$first_car_model = ????????????;$last_car_model = ????????????;

$my_post = array();$my_post['ID'] = $post_id;$my_post['post_title'] = $car_name . ' - ' .$first_car_model . ' ~ ' . $last_car_model; remove_action('save_post', 'change_title_cars'); wp_update_post($my_post );
}
}

//Save ACF fields as post_content for front-end

function change_title_frontend_cars($post_id) { global$_POST;
if('cars'== get_post_type()){

$car_name = get_post_meta($post_id,'car_name',true);
$first_car_model = ????????????;$last_car_model = ????????????;

$my_post = array();$my_post['ID'] = $post_id;$my_post['post_title'] = $car_name . ' - ' .$first_car_model . ' ~ ' . $last_car_model; remove_action('acf/save_post', 'change_title_frontend_cars'); wp_update_post($my_post );
}
}


I’m using a repeater which has a sub-field named “car_model”. I’m trying to have the title changed into something like this:

(car_name) – (first “car_model” in the repeater) ~ (last “car_model” in the repeater)

but I couldn’t get values of the repeater sub-fields inside the function.

Note: the repeater has random number of rows.

0
1 year 2020-07-15T01:11:05-05:00 0 Answers 42 views 0