Home Forums ACF PRO Oembed and repeater


Oembed and repeater

  • I need to work separately with the different oembed rows within a repeater field.

    For example, I need to embed the first video within an oembed repeater field and display the thumbnail image from the first video. I had this working in AFC 4 but upgrading to Pro appears to require a new code.

    I have been able to embed the video using the following code:

    $rows = get_field('video'); // get all the rows
    				$first_row = $rows[0]; // get the first row
    				$first_video = $first_row['video_embed']; // get the sub field value 
    				$first_video_embed = wp_oembed_get($first_video);

    Q1 – Is this the correct approach?

    Q2 – How do I get the thumbnail image?

    The code used to be – $first_video_thumbnail = $first_video->thumbnail_url;

    Thanks very much in advance!


  • Hi @roberthindle

    I’m afraid you need to create a custom function to parse the URL and get the thumbnails. Here’s a thread on the same topic:

    I hope this helps 🙂

  • Thanks James.

    Sadly this particular code doesn’t work for vimeo. I stepped through the function and found that it was receiving a 404 error from vimeo (with what the documentation says is an accurate url). I understand that vimeo changed something a while back so it may be outdated. (this being what has prompted this exercise for me as we suddenly lost all our vimeo embeds with ACF 4.)

    You’ve sent me in the right direction however.

    Also a note to anyone else reading – my markup above doesn’t require the wp_oembed_get() code. I had a mistake in my customfield setup where the oembed field had ‘changed’ to text format.

    Correct video code with oembed correctly setup is

    	$rows = get_field('video'); // get all the rows
    	$first_row = $rows[0]; // get the first row
    	$first_video = $first_row['video_embed']; // get the sub field value
    echo $first_video;

    If anyone has a recent working solution to this then I’m all ears! It’s not as if this is an unusual use case. 🙂

  • Hi @roberthindle

    That’s weird. I’ve just tested the code and it’s working as it should. Could you please share an example of the video URL that has the issue? If it’s sensitive data, you can post the reply as private so no one else can see it.

    Thanks 🙂

  • The joys of code!

    The youtube aspect worked great for me, it was just the vimeo side. I solved this by replacing the get_vimeo_uri function with the code example provided by vimeo here –

    I had to make a small tweak to pass the full url rather than just the id.

    function get_vimeo_thumbnail_uri( $clip_id ) {
    		$clip_id = ''.$clip_id;
    		$oembed_endpoint = '';
    // Grab the video url from the url, or use default
    $video_url = ($_GET['url']) ? $_GET['url'] : $clip_id;
    // Create the URLs
    $json_url = $oembed_endpoint . '.json?url=' . rawurlencode($video_url) . '&width=640';
    $xml_url = $oembed_endpoint . '.xml?url=' . rawurlencode($video_url) . '&width=640';
    // Curl helper function
    function curl_get($url) {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        $return = curl_exec($curl);
        return $return;
    // Load in the oEmbed XML
    $oembed = simplexml_load_string(curl_get($xml_url));
        An alternate approach would be to load JSON,
        then use json_decode() to turn it into an array.
    return $oembed->thumbnail_url;		
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Oembed and repeater’ is closed to new replies.