Support

Account

Home Forums Backend Issues (wp-admin) Fill field with remote data? Reply To: Fill field with remote data?

  • Oh, also just going to post my code in case it’s helpful or if someone wants to yell at me for being wrong:

    	// Fetch vimeo thumbnail on save - takes video ID as input
    	function rf_acf_update_vimeo_thumb( $value, $post_id, $field ) {
    		// only set a new value if the field is empty
    		if ( $value == '') {
    			// get video here
    			$vimeo_video_id = get_field('vimeo_video_id');
    			// fetch thumb url(s)
    			$vimeo_meta = file_get_contents("https://vimeo.com/api/v2/video/$vimeo_video_id.json");
    			$vimeo_meta = json_decode($vimeo_meta);
    			$vimeo_thumb = $vimeo_meta[0]->thumbnail_large;
    			// set value
    			$value = $vimeo_thumb;
    			return $value;
    		} else {
    			return $value;
    		}
    	}
    	
    	add_filter('acf/update_value/name=thumbnail_url', 'rf_acf_update_vimeo_thumb', 10, 3);