{"id":18460839,"date":"2025-05-12T06:55:52","date_gmt":"2025-05-12T06:55:52","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/daily-posts-plugin\/"},"modified":"2025-05-12T06:55:52","modified_gmt":"2025-05-12T06:55:52","slug":"daily-posts-plugin","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/daily-posts-plugin\/","title":{"rendered":"Daily Posts plugin"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&lt;?php<\/strong><br \/><br \/>\/**<br \/><br \/>* Shortcode to display posts published on the current day and month, across all years.<br \/><br \/>*<br \/><br \/>* Usage: &#091;daily_on_this_day_posts]<br \/><br \/>*\/<br \/><br \/>function display_daily_posts_on_this_day_shortcode() {<br \/><br \/>\/\/ Get the current day and month<br \/><br \/>\/\/ 'j' for day of the month without leading zeros (1 to 31)<br \/><br \/>\/\/ 'n' for month number without leading zeros (1 to 12)<br \/><br \/>$current_day = date('j');<br \/><br \/>$current_month = date('n');<br \/><br \/>\/\/ Arguments for the WordPress query<br \/><br \/>$args = array(<br \/><br \/>'post_type' =&gt; 'post', \/\/ We are querying standard posts<br \/><br \/>'post_status' =&gt; 'publish', \/\/ Only show published posts<br \/><br \/>'posts_per_page' =&gt; -1, \/\/ Retrieve all posts that match the criteria<br \/><br \/>'date_query' =&gt; array( \/\/ This is the key part for matching the date<br \/><br \/>array(<br \/><br \/>'month' =&gt; $current_month, \/\/ Match the current month<br \/><br \/>'day' =&gt; $current_day, \/\/ Match the current day<br \/><br \/>\/\/ Year is intentionally omitted to match across all years<br \/><br \/>),<br \/><br \/>),<br \/><br \/>'orderby' =&gt; 'date', \/\/ Order the results by their full publication date<br \/><br \/>'order' =&gt; 'DESC', \/\/ Show the newest posts first (e.g., from most recent year)<br \/><br \/>'ignore_sticky_posts' =&gt; 1, \/\/ Do not let sticky posts interfere with the date order<br \/><br \/>\/\/ By default, WP_Query searches all categories, so no need to specify category exclusion explicitly<br \/><br \/>);<br \/><br \/>$daily_posts_query = new WP_Query($args);<br \/><br \/>\/\/ Prepare the output string<br \/><br \/>$output = '';<br \/><br \/>\/\/ Get the current date formatted nicely for the title (e.g., \"May 12th\")<br \/><br \/>$current_date_formatted = date('F jS'); \/\/ Using 'F jS' for \"Month daySuffix\", e.g., \"May 12th\"<br \/><br \/>if ($daily_posts_query-&gt;have_posts()) {<br \/><br \/>$output .= '&lt;h2&gt;Posts from ' . esc_html($current_date_formatted) . ' (Across All Years)&lt;\/h2&gt;';<br \/><br \/>\/\/ Removed the &lt;ul&gt; tag<br \/><br \/>while ($daily_posts_query-&gt;have_posts()) {<br \/><br \/>$daily_posts_query-&gt;the_post();<br \/><br \/>\/\/ Each post is now a separate div block<br \/><br \/>$output .= '&lt;div class=\"daily-post-entry\" style=\"margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid #eee; overflow: hidden;\"&gt;'; \/\/ Added overflow:hidden to contain floats<br \/><br \/>\/\/ Display the featured image if it exists, floated to the left<br \/><br \/>if (has_post_thumbnail()) {<br \/><br \/>\/\/ You can change 'thumbnail' to other sizes like 'medium', 'large', or a custom size<br \/><br \/>\/\/ Added float:left and margin for spacing<br \/><br \/>$output .= '&lt;div class=\"daily-post-image\" style=\"float: left; margin-right: 15px; margin-bottom: 10px; max-width: 150px;\"&gt;'; \/\/ Added max-width to control image size<br \/><br \/>$output .= get_the_post_thumbnail(get_the_ID(), 'thumbnail'); \/\/ Using 'thumbnail' size<br \/><br \/>$output .= '&lt;\/div&gt;';<br \/><br \/>}<br \/><br \/>\/\/ Container for the text content, to allow it to flow next to the image<br \/><br \/>$output .= '&lt;div class=\"daily-post-content\" style=\"overflow: hidden;\"&gt;'; \/\/ overflow:hidden helps contain content next to float<br \/><br \/>\/\/ Display the post title as a link<br \/><br \/>$output .= '&lt;h3&gt;&lt;a href=\"' . esc_url(get_permalink()) . '\"&gt;' . esc_html(get_the_title()) . '&lt;\/a&gt;&lt;\/h3&gt;';<br \/><br \/>\/\/ Display the full publication date<br \/><br \/>$output .= '&lt;p style=\"font-size: 0.9em; color: #555; margin-top: 0;\"&gt;Published on: ' . esc_html(get_the_date('F jS, Y')) . '&lt;\/p&gt;'; \/\/ e.g., May 12th, 2023<br \/><br \/>\/\/ Display the excerpt<br \/><br \/>$output .= '&lt;div style=\"margin-top: 5px;\"&gt;' . get_the_excerpt() . '&lt;\/div&gt;';<br \/><br \/>$output .= '&lt;\/div&gt;'; \/\/ End of daily-post-content<br \/><br \/>\/\/ $output .= '&lt;div style=\"clear: both;\"&gt;&lt;\/div&gt;'; \/\/ Optional: explicit clear if overflow:hidden on parent isn't enough in some themes<br \/><br \/>$output .= '&lt;\/div&gt;'; \/\/ End of daily-post-entry<br \/><br \/>}<br \/><br \/>\/\/ Removed the &lt;\/ul&gt; tag<br \/><br \/>wp_reset_postdata(); \/\/ Important: Restore original post data after custom loop<br \/><br \/>} else {<br \/><br \/>$output .= '&lt;p&gt;No posts found for ' . esc_html($current_date_formatted) . ' from any year.&lt;\/p&gt;';<br \/><br \/>}<br \/><br \/>return $output; \/\/ Return the HTML to be displayed by the shortcode<br \/><br \/>}<br \/><br \/>\/\/ Register the shortcode so WordPress recognizes it<br \/><br \/>add_shortcode('daily_on_this_day_posts', 'display_daily_posts_on_this_day_shortcode');<br \/><br \/><strong>?&gt;<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rich<\/p>\n","protected":false},"template":"","class_list":["post-18460839","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18460839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18460839\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18460839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}