Last active
August 29, 2015 14:19
-
-
Save cklosowski/105ee825cf9d21176dc5 to your computer and use it in GitHub Desktop.
Gives a shortcode of [on_this_date] to display posts from this day, in all years from a site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: On This Date | |
Plugin URI: https://kungfugrep.com/ | |
Description: Gives a shortcode [on_this_date] to show posts from this day of the month in all years | |
Version: 0.1 | |
Author: Chris Klosowski | |
Author URI: https://kungfugrep.com | |
License: GPLv2 or later | |
*/ | |
function ck_from_this_date() { | |
$args = array( | |
'orderby' => 'post_date', | |
'order' => 'DESC', | |
'cat' => <category_id>, | |
'date_query' => array( | |
array( | |
'month' => date('m'), | |
'day' => date('d'), | |
), | |
), | |
); | |
$new_query = new WP_Query( $args ); | |
if ( $new_query->have_posts() ) { | |
while ( $new_query->have_posts() ) { | |
$new_query->the_post(); | |
?> | |
<?php echo the_date(); ?> | |
<div> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
</div> | |
<?php | |
} | |
} else { | |
?><div><em>No posts found.</div><?php | |
} | |
wp_reset_postdata(); | |
} | |
add_shortcode( 'on_this_date', 'ck_from_this_date' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment