Skip to content

Instantly share code, notes, and snippets.

@samazgor
Last active March 4, 2016 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samazgor/e894d704a16e024493d8 to your computer and use it in GitHub Desktop.
Save samazgor/e894d704a16e024493d8 to your computer and use it in GitHub Desktop.
Display your posts from this exact day in previous years in WordPress
/**
*
* Time Capsule By Sam Azgor
* Copy and paste the following code in your theme’s functions.php file
* Add this to your template - <?php wp_timehop_sam(); ?>
*
*/
function wp_timehop() {
$today = getdate();
$the_query = new WP_Query( '&monthnum=' . $today['mon'] . '&day=' . $today['mday'] );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment