I need to embed the last posted video (from a specific category) to the frontpage of my Wordpress site. Is there any shortcode (or widget, even) I can use to simply filter my posts by category, and have the content (in this case, an embedded .wmv or .m4v) displayed based on a "last posted" basis. I am currently able to get a simple static embed working, but I need the embed to be dynamic based on the last video posted. The video cannot be hosted on sites like youtube or vimeo; I need to have them hosted as video files on a server and embed them that way.

Thanks in advance.


1 Answer 1


This should work, even outside of the loop:

$latestPost = get_posts('numberposts=1&category=YOUR_CATEGORY_ID');

The Wordpress function get_posts sorts by post date, newest-to-oldest by default, so you'd get the newest post in whatever category you choose. Also, even though you are only requesting one post, the response will still be an array:

echo $latestPost[0]->post_content;


Since the video embed code is being provided by a plugin that uses a shortcode, you'll have to use the function do_shortcode on the content. If there is text (content other than the video) you'll have to parse out the shortcode from the post_content.

  • Thank you for the quick reply. I have tried getting a similar method working, however when I echo the post contents, all I get is text. I am using the mediaelements plugin, which allows me to embed wmvs into posts. The embed works, but only when I view the actual post, not the "post contents". So when I echo the post contents to my frontpage, all that is displayed is the shortcode text (in this case, [video src="video.mp4"]). I'm really not sure if I'm overlooking something here, or if Wordpress just disallows the type of embedding I need for security and this is not possible.
    – David
    Dec 7, 2011 at 19:35
  • Ah! In that case, use the function do_shortcode to get the actual embed. I would imagine that you'll have to parse out the shortcode, in case the post has some text too.
    – The Maniac
    Dec 7, 2011 at 19:53
  • Awesome! Thanks alot for the help. I never knew Wordpress had such a large library of functions and calls. Looks like I have some reading to do over the holidays.
    – David
    Dec 7, 2011 at 20:01

Your Answer

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