Home › Forums › ACF PRO › auto fill ACF input using iTunes Search API Value › Reply To: auto fill ACF input using iTunes Search API Value
I am on a roll answering everyone’s questions today so here we go with another…
This function will run every time a field is updated to check if your field needs to be checked. If your field is found it checks the value to see if it has changed since last update. If it has it will run your api call and update the other fields necessary as declared by you.
function my_acf_update_value( $value, $post_id, $field ) {
// only do it to certain custom field
if( $field['name'] == 'custom_field_name' ) {
// get the old (saved) value
$old_value = get_field('custom_field_name', $post_id);
// get the new (posted) value
$new_value = $_POST['acf']['field_1234567890abc'];
// check if the old value is the same as the new value
if( $old_value != $new_value ) {
// do your api call functions and return you size and what not
update_field('sizeField',$sizeValue, $post_id);
}
}
// don't forget to return to be saved in the database
return $value;
}
// acf/update_value - filter for every field
add_filter('acf/update_value', 'my_acf_update_value', 10, 3);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.