0

I have added a custom field to 2 posts in order for a non-developer to be able to post a video link from YouTube, and put the embed id in a custom field to be called by the code below. But when I tried to execute it I get "An error occurred, please try again later." Upon inspection I find that it is trying to call the link as "https://www.youtube.com/embed/Array" instead of filling in the youtubeId.

<iframe width="100%" height="100%" src="https://www.youtube.com/embed/<?php echo get_post_meta(93,'youtubeId');?>" frameborder="0" allowfullscreen></iframe>

There is the code I am trying to run in a <div> in order to embed a YouTube link dynamically. Basically it is a lot easier for my non-developer content managers to edit a Wordpress post with an updated video than go changing the link in the actual page PHP/HTML.

1 Answer 1

1

By default get_post_meta returns an array. If you wish to return a single value you need to set the 3rd parameter to true.

Eg.

get_post_meta(93, 'youtubeId', true);

And did you know that your client can just paste a youtube URL into the Wordpress editor and it will auto-embed that video?

get_post_meta

1
  • Thank you that was it. No client here. Just me and my gaming community. I know I can embed in the posts but I want to embed on the home page so this was the best way to do it that I could figure out. Thank you very much for your help. I really appreciate it.
    – Weber
    Oct 12, 2016 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.