Support

Account

Home Forums ACF PRO Getting just the url that was entered into an oEmbed field inside a variable

Solved

Getting just the url that was entered into an oEmbed field inside a variable

  • Hi,

    Can someone please tell me if it is possible to get just the url from an oEmbed field inside a variable?

    The following code works great as a text field but not as an oEmbed field:

    $youtube_video_url = get_field('youtube_video_url');
    if ( $youtube_video_url !== '' && validate_youtube_video( $youtube_video_url ) == TRUE )	 {
     // do stuff
    }
  • Hi @UncleBob1846

    You can get the url saved in the database by using the $format_value parameter like so:

    
    $youtube_video_url = get_field('youtube_video_url', false, false);
    
  • I can’t seem to make this work with my repeater. Here’s my code:

    if(have_rows('videos')): while(have_rows('videos')): the_row();
        $video_embed_url = get_sub_field('video_embed', false, false);
        $thumbnail = get_sub_field('thumbnail');
        $thumbnail_url = $thumbnail['url'];
        echo '<a href="' . $video_embed_url . '"><img src="' . $thumbnail_url . '" /></a>';
    endwhile; endif;

    It’s outputting the whole iframe embed code, not the URL entered into the oEmbed field. Also, nothing changes if I remove ‘false, false’ from that get_sub_field.

  • Hi @AKA Digital

    Thanks for the comment, the get_sub_field (or any sub field functions) do not contain a parameter for $format_value, so the value will all ways be formatted.

    To get the un-formatted (raw) sub field data, you will need to load the repeater field without formatting like so:

    
    $repeater = get_field('videos', false, false);
    

    If you place this before your have_rows call, this should update the cache with a value that is not formatted.

    I agree that this is a bug and should be fixed. I’ll have a look at finding a solution for this later today

  • Hi @Elliot Condon,

    Thanks so much for the help. Your solution worked, though I had to change my whole loop because I was no longer able to access fields by their field names, instead I had to use the database name thingies that look like this: ‘field_5445285988c8b’ and I needed different code for the image since the returned value for that was changed, and I had to add a new field for the title as I couldn’t figure out how to get the title attribute from the image in WordPress. Not sure how complicated things would get with other kinds of fields, but for now it’s working great with those minor changes.

    If you were wondering, the reason for all this is so the user can see an immediate preview of their youtube video in the backend, and it’s easier for them to paste an entire YouTube link rather than getting the 11-character video ID from the URL, which is how I’ve done it in the past.

  • I think this option should be included as a choice option when building the oembed fields, something like:

    return type : 1) embed code, 2) url video

    Often people need url only.

  • Event better, allow the option to return the full oEmbed data object.

    That way height/width could be extracted server side when appropriate (for responsive videos with non-standard aspect ratios), etc. It would also allow you to grab the thumbnail path.

    And it eliminates the issues of not being able to return the raw unformatted entry within repeater, flexible content and group fields.

  • Works: get_post_meta( $post_id, ‘video’, true );
    So don’t use get_field, as far I can see only URL is stored in database.

  • While I too would like the option to return a type embed the iframe code or just the url…

    I separately ran into a challenge that might for some of us be caused by header Permissions Policy settings at a server level nginx/ajax mentioned in this article.

    Also, be careful if there if someone working inside your vimeo account has created more than one embed Preset in case fullscreen is checked in one preset and unchecked in another… and it gets complicated if you update things and check the box to update all videos. (not always an immediate update)

    More details at stackexchange for whomever might need some extra options besides pointing at ACF or WP core or whatever other thing. https://stackoverflow.com/questions/67720466/embedded-vimeo-iframe-fullscreen-not-working-in-chrome

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

The topic ‘Getting just the url that was entered into an oEmbed field inside a variable’ is closed to new replies.