Skip to content

Instantly share code, notes, and snippets.

@dallasread
Last active August 29, 2015 14:05
Show Gist options
  • Save dallasread/183bbd0c9552cf3e82bf to your computer and use it in GitHub Desktop.
Save dallasread/183bbd0c9552cf3e82bf to your computer and use it in GitHub Desktop.
A Wordpress template that redirects to your latest post.
<?php
/*
Template Name: Latest Post Redirect
This page template will redirect to your latest post.
Simply create a new page and set the template as "Latest Post Redirect".
For specific categories, see http://codex.wordpress.org/Function_Reference/wp_get_recent_posts.
*/
$recent_posts = wp_get_recent_posts( array(
'numberposts' => 1,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
) );
wp_redirect( get_permalink($recent_posts[0]["ID"]), 302 );
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment