In WordPress, I have a custom post-type “videos”. Now on the edit (regular) posts page, I would like to have a field “featured video” that allows me to select a video from all the videos of the custom post-type “videos”.
Where do I start?
PS: No plug-ins, please.
Easy Way:
Create a Custom Field (enable Custom Fields by clicking Screen Options in the upper right-hand corner of your edit page) and call it “featuredVideo” with a value of the ID of the video you want to link to.
Then call in your single post template like so:
Best Way:
You can Add A Meta Box to your post editor with a simple dropdown to select from all Posts of type Video. This will require a decent chunk of code in your functions.php, and you will still need to store the information as metadata, but it gives you a clean interface to work with, and you no longer have to keep track of IDs to make it work.
functions.php –
The above example is untested, so I can’t guarantee it will work straight out of the gate, but the hard part is essentially done for you if that’s the approach you want to take. Once you get your custom Meta Box working, you can reference the post metadata in your single post template in exactly the same fashion I used in the first example.
Just play around with it, and see what works best for you.