PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Using form to submit posts - custom fields

  1. I am in the process of setting up a form which will allow users to make an entry to the site. I am wanting them to be able to enter youtube embed code - currently this is being placed in a custom field, but I was wondering if it were possible to have this so it posted into the post body?

    Posted 12 years ago on Tuesday July 12, 2011 | Permalink
  2. You can do this. Don't have them enter the embed code though. Just have them enter the YouTube URL. Then in your Content Template for the post body, insert the custom field where they entered the YouTube URL (before or after the other form fields they submitted, however you want it laid out.)

    In your admin, under Options > Media (http://example.com/wp-admin/options-media.php) there is a section (mid-way down) called "Embeds":

    Auto-embeds: When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube. When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube.

    Make sure you check that. In WordPress since 2.9, they use oEmbed to "auto-embed" YouTube and Flickr and all sorts of things - all you need to insert is the URL. You can read more about it here.

    Simple, sample form:
    http://guitar.chrishajer.com/2011/07/11/submit-a-youtube-video-to-our-contest/

    Enter a YouTube URL there and it should work fine. I have the post set to publish automatically. You'll have to go to the home page of the site to see your post.

    For my post body, I have only this:
    [embed]{YouTube:7}[/embed]

    The embed shortcode is optional, but it lets you do other things (like specify width and height if you want to.) I tried without wrapping my custom field in the shortcode, in the content template, and it worked that way on my site as well. To be safe, the embed shortcode cannot hurt you.

    So, yes you can do this, without a doubt. You might want to do some sort of validation on the YouTube URL and have the posts made as drafts, but as you can see in this simple example, it works fine.

    Posted 12 years ago on Tuesday July 12, 2011 | Permalink
  3. Just tested with a couple other oEmbed enabled sites that are whitelisted by WordPress, and they work as well. Awesome.

    Posted 12 years ago on Tuesday July 12, 2011 | Permalink
  4. Thanks Chris! That was just what I was looking for!

    Posted 12 years ago on Tuesday July 12, 2011 | Permalink

This topic has been resolved and has been closed to new replies.