Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Show related (archive) month and year to post

Use following code after the loop:

$month_num = get_the_date('n');
$month_txt = get_the_date('F');
$year = get_the_date('Y');

// change 'posts_per_page' to any value you need, '-1' means 'all'
query_posts( 'posts_per_page=-1&monthnum='.$month_num.'&year=".$year );

echo "<p class="">Archived in '.$month_txt.', '.$year.'</p>';
echo '<ul>';

while ( have_posts() ) : the_post();
    echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
endwhile;

echo '</ul>';
wp_reset_query();

It’s not tested, but you got the idea.

Related Posts:

  1. How to check if post meta key exists or not in wordpress database
  2. How to add category to: ‘wp-admin/post-new.php’?
  3. How can I retrieve multiple get_post_meta values efficiently?
  4. Code to make a post sticky
  5. How to allow hidden custom fields to be added from wp-admin/post.php?
  6. Export WordPress Posts and Meta Information in CSV format
  7. Delete duplicated wp_postmeta record
  8. Will a large postmeta table slow a site down?
  9. Update all posts automatically when using post_meta
  10. How to batch update post content with custom post meta value
  11. Change slug with custom field
  12. Better post meta efficiency?
  13. Setting post meta data to random value during post status transition / on publish
  14. Edit meta data does’t work with custom sql
  15. Human Time Diff, change mins to minutes
  16. Change post format using custom field
  17. Does WP get all post_meta on POST page?
  18. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  19. Exporting Data from WordPress into a flat table
  20. Adding Multiple Values to a Post Meta Key
  21. Using radio button meta data from a custom meta box
  22. PHP Notice error (when on 404 page)
  23. What Is meta_id In wp_postmeta?
  24. Checking if a post with certain meta value exists
  25. How to permanently delete a post meta entry?
  26. Add custom field automatically (add_post_meta) with value based on number of words of article
  27. How to generate numbers indistinguishable for the IDs of the posts
  28. Modify WP_Post before processing
  29. Save re-arranged draggable post items to wordpress database
  30. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  31. Change post_date to post_modified date on post template?
  32. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  33. How can I sort posts by the date and a custom meta field?
  34. is there a way to show the the post title after the image?
  35. Get Meta Key Value While Saving Post
  36. Force the “Choose from the most used tags” meta box section to always be expanded
  37. Meta value does not save for scheduled posts
  38. Custom Posts Query and meta_query Sort Order
  39. How to compare two posts including their meta fields on a scalable base?
  40. Getting value from get_post_custom
  41. Calling Different Custom Post Timestamps in a table
  42. Is it possible to paste a link without tags and make it directly a link in a post?
  43. Cannot retrieve a custom RSS field from posts
  44. Saving custom fields to a custom taxonomy
  45. How to automate featured posts number? [duplicate]
  46. Customize rel=canonical tag for single blog post
  47. Change all author links in Blog roll
  48. How to I retrieve the ID from the Posts page?
  49. How to save meta checkbox WordPress
  50. How to calculate the average of a post meta value(Numeric) of a specific author
  51. Is there any way to tell when wp_postmeta has been updated?
  52. wpColorPicker – problem with implementation to post meta
  53. Change post author without using wp_update_post()
  54. if in category but only with post meta
  55. wp_query with ajax
  56. Update post meta within save_post action
  57. Display post number by category
  58. Updating post meta for checkbox
  59. Saving Post Data in Another Database
  60. Custom permalink for each post
  61. How can I tell if a post has been published at least once?
  62. Private post caught in endless redirect loop
  63. How to retrieve all meta data directly from the $post object? Such as $post->related_topics?
  64. What is proper filter or hook action to add data to the $post object?
  65. Blogposting Schema & Structured Data without plugin
  66. Automatically select template based on query string for New Posts
  67. Display Updated Date Instead of Published Date
  68. How do you update post date (year only) in a separate custom field?
  69. Add postmeta to all blog posts
  70. Bulk Post update_post_meta
  71. Re-order Category Meta-data
  72. How to hide meta from search result only on pages?
  73. WP_Query sort by meta_value_num or date
  74. Grab meta data before post is saved
  75. How to fetch posts that are stored in the different table than the default table (wp_posts)?
  76. Check if user has avatar
  77. alt of attached image in post / pages
  78. Creating Ordered Query using Meta_key
  79. Best Way to detect unique posts in wp rest api
  80. Get the correct meta_value with get_post_meta
  81. post_name is not stored until post is published… where should I store my slug until it goes live then?
  82. Filter question list on substring of metavalue
  83. Add a meta to a post submited from a frontend form
  84. Show posts between two Custom Fields date
  85. Add custom class to existing menu items from custom meta
  86. How to get only current images of a post
  87. Ordering posts alphabetically by meta keys and title
  88. Run function after post is updated
  89. Where should get_post_meta() go to get $post->ID get_post_meta() is empty and $post->ID & get_the_id() are working
  90. Adding custom fields to the Quick Edit screen – puzzled about the column concept
  91. How enter custom post meta or custom field on box post list archive page?
  92. WP_query sort by custom meta_key “price”
  93. If meta_key exists then don’t select this post?
  94. NewsPaper WP Theme – Additional Related Posts Filter by Time (divTag composer)
  95. What effect can a large wp_post table have on overall site performance?
  96. Site ‘Categories’: save an admin global setting with post metadata [closed]
  97. How to make internal links creating plugin to respect ACF?
  98. Translation related post text to Arabic
  99. WordPress post meta key and value lookup
  100. How can I create Woodmart theme “linked variations” through REST API?
Categories posts Tags post-meta, posts
Saving Revision of post meta key/value on each update_post_meta event
update_post_meta not working

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress