Title: Daily Posts plugin
Last modified: May 12, 2025

---

# Daily Posts plugin

 *  [Richard Brown](https://wordpress.org/support/users/cregy/)
 * (@cregy)
 * [1 year ago](https://wordpress.org/support/topic/daily-posts-plugin/)
 * Hi
 * I had this idea a while ago to create a plugin to show the posts on today excluding
   category and year. I asked Gemini to help with the code and this is what it has
   come up with:
 *     ```wp-block-code
       <?php/*** Shortcode to display posts published on the current day and month, across all years.** Usage: [daily_on_this_day_posts]*/function display_daily_posts_on_this_day_shortcode() {// Get the current day and month// 'j' for day of the month without leading zeros (1 to 31)// 'n' for month number without leading zeros (1 to 12)$current_day = date('j');$current_month = date('n');// Arguments for the WordPress query$args = array('post_type' => 'post', // We are querying standard posts'post_status' => 'publish', // Only show published posts'posts_per_page' => -1, // Retrieve all posts that match the criteria'date_query' => array( // This is the key part for matching the datearray('month' => $current_month, // Match the current month'day' => $current_day, // Match the current day// Year is intentionally omitted to match across all years),),'orderby' => 'date', // Order the results by their full publication date'order' => 'DESC', // Show the newest posts first (e.g., from most recent year)'ignore_sticky_posts' => 1, // Do not let sticky posts interfere with the date order// By default, WP_Query searches all categories, so no need to specify category exclusion explicitly);$daily_posts_query = new WP_Query($args);// Prepare the output string$output = '';// Get the current date formatted nicely for the title (e.g., "May 12th")$current_date_formatted = date('F jS'); // Using 'F jS' for "Month daySuffix", e.g., "May 12th"if ($daily_posts_query->have_posts()) {$output .= '<h2>Posts from ' . esc_html($current_date_formatted) . ' (Across All Years)</h2>';// Removed the <ul> tagwhile ($daily_posts_query->have_posts()) {$daily_posts_query->the_post();// Each post is now a separate div block$output .= '<div class="daily-post-entry" style="margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid #eee; overflow: hidden;">'; // Added overflow:hidden to contain floats// Display the featured image if it exists, floated to the leftif (has_post_thumbnail()) {// You can change 'thumbnail' to other sizes like 'medium', 'large', or a custom size// Added float:left and margin for spacing$output .= '<div class="daily-post-image" style="float: left; margin-right: 15px; margin-bottom: 10px; max-width: 150px;">'; // Added max-width to control image size$output .= get_the_post_thumbnail(get_the_ID(), 'thumbnail'); // Using 'thumbnail' size$output .= '</div>';}// Container for the text content, to allow it to flow next to the image$output .= '<div class="daily-post-content" style="overflow: hidden;">'; // overflow:hidden helps contain content next to float// Display the post title as a link$output .= '<h3><a href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a></h3>';// Display the full publication date$output .= '<p style="font-size: 0.9em; color: #555; margin-top: 0;">Published on: ' . esc_html(get_the_date('F jS, Y')) . '</p>'; // e.g., May 12th, 2023// Display the excerpt$output .= '<div style="margin-top: 5px;">' . get_the_excerpt() . '</div>';$output .= '</div>'; // End of daily-post-content// $output .= '<div style="clear: both;"></div>'; // Optional: explicit clear if overflow:hidden on parent isn't enough in some themes$output .= '</div>'; // End of daily-post-entry}// Removed the </ul> tagwp_reset_postdata(); // Important: Restore original post data after custom loop} else {$output .= '<p>No posts found for ' . esc_html($current_date_formatted) . ' from any year.</p>';}return $output; // Return the HTML to be displayed by the shortcode}// Register the shortcode so WordPress recognizes itadd_shortcode('daily_on_this_day_posts', 'display_daily_posts_on_this_day_shortcode');?>
       ```
   
 * Should I simply post the code in the functions file or would it be better to 
   create a plugin and update on a regular basis please? Is the code ok?
 * Thanks
 * Rich
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdaily-posts-plugin%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Mainul Kabir Aion](https://wordpress.org/support/users/aion11/)
 * (@aion11)
 * [1 year ago](https://wordpress.org/support/topic/daily-posts-plugin/#post-18461104)
 * Hi,
 * Its better to create a custom plugin and update when needed. Otherwise, it will
   be removed when you update the core WordPress version. If the code works, go 
   for it!
 * Thanks.
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [1 year ago](https://wordpress.org/support/topic/daily-posts-plugin/#post-18461208)
 * The code is syntactically and contextually correct, but does not comply with 
   WordPress Coding Standards. These are basics according to which plugins and themes
   in WordPress should be developed. See: [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/)
 * If it works for you, use it. I would recommend integrating the code via [a code snippet plugin](https://wordpress.org/plugins/tags/snippets/)
   if you don’t want to make your own plugin out of it. For future codes, however,
   it might be better not to rely on an AI, as these could also contain security
   vulnerabilities.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Daily Posts plugin’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 3 participants
 * Last reply from: [threadi](https://wordpress.org/support/users/threadi/)
 * Last activity: [1 year ago](https://wordpress.org/support/topic/daily-posts-plugin/#post-18461208)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
