Support

Account

Home Forums ACF PRO auto fill ACF input using iTunes Search API Value

Solved

auto fill ACF input using iTunes Search API Value

  • i’m using iTunes api to load app information into my post inside front end view.
    i’m looking for a way to add app id inside an acf field and get values from that id using iTunes Search APi and put it into other acf field.

    for example now i have to create an acf field named APPID and retunr it in single.php file and show information of that app like echo $FileSize or …

    what i need is to create an extra acf field name FileSize and fill it automaticaly with data comes from my iTunes Search Api in backend.

    can you help me with this or give me a hint on how can i do this please ?

  • 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);
    
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.