Forum Replies Created

  • I’ve also discovered that if you add a term in this field and then remove it again – it doesn’t remove the term.

  • 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;		
  • 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. πŸ™‚

Viewing 4 posts - 1 through 4 (of 4 total)