It depends on how your archives.php
is designed.
You can use built-in wp_get_archives()
function to get posts for last 12 months:
<?php
wp_get_archives(
array(
'type' => 'monthly',
'limit' => 12
)
);
as described in the Codex.
Or you can modify the WP_Query
using 'date_query'
parameter:
<?php
$args = array(
'date_query' => array(
array(
'after' => strtotime("-1 year"), // a year before
'before' => strtotime("now");, // now
'inclusive' => true, // false to exclude first and last day
)
)
);
$query = new WP_Query( $args );
as also described there.
Related Posts:
- Custom Post Type Archive.php
- how do I add a button in each category to display all posts?
- How best to create a variation of an archive template work?
- How To Get the Correct Character length of the Category Archives Page Title
- How to get the archive post type/format in the loop?
- Override the else part of the index.php loop.
- How to set number of posts to display in archive
- Category Archive
- Custom Post Type Settings page, choose page to display archive
- How To Create A Paginated List Of All Categories On My Site?
- How to get the custom post type from an archive page?
- Add custom field to the archive page?
- Display page of custom posts?
- Landing in 404 Page on Navigating to Custom Taxonomy Archive
- How to make a custom Archive Page
- WooCommerce Link to Product Category
- Which php file lists all the post of a category
- How do I change the sql query for wp_get_archive()
- Last post is not showing up
- Custom template for archive of a custom taxonomy
- WordPress custom post type archive with description
- Custom query in archive.php with pagination nightmare
- Double count view in archive.php
- Custom post type and taxonomy permalinks – Structure
- creating custom archive template within plugin for custom post type using archive_template filter
- WordPress subcategories return 404 in custom template
- Custom post type is showing custom home page, not archive page
- Why is the custom taxonomy archive page redirecting me to a single post? [closed]
- Isotope Filtering with Bootstrap Tabs – Custom Post Type Query Loop in each Tab (Have to click twice to filter)
- Restoring default article pagination on archives – Removing custom limits
- Duplicated posts on category page
- Only one post is showing on category page, why?
- How to override p2 breathe theme plugin in content template file?
- Custom Taxonomy index/archive hierarchy
- Increase 10 post limit per page
- Custom Post Type Archive template page not found
- My archive-posttype.php template is not loading
- Custom Post Archive is not working
- Get current title of archive.php
- How to list articles by year based on url?
- WordPress override archive page template using a plugin
- archive_template override when no posts exist
- Display custom post types in wp_list_pages
- How to customize taxonomy archive template files for subterms?
- Archive template combined with post slider and regular posts
- Is it possible to have a template that works on multiple categories where the link address contains the specific category?
- Image loading function not working on archive.php template
- How to add html code at the bottom of the post in archive page?
- Taxonomy template page not working
- How to get the Custom Post Type Archive inside a folder
- CPT with its own category and tag url
- Custom Post Type Archive template not being called
- Limiting the Archive page to posts posted by particular author
- Can’t replace the default sidebar with a custom sidebar on Custom Post Type in Genesis
- Highlight archive link on single.php
- Ascending order of yearly archives [closed]
- How to Fix an Archive.php That Displays All Posts?
- How do I create an alphabetically organized glossary of links?
- Is possible register two archive pages for single custom post type?
- Links to previous/next month archives
- How to create archive page to add in menu
- Make the home page template my archive/category page template without code duplication
- Strange behaviour of hierarchical taxonomy archive
- Why is my archive page looping through all but one post?
- Template taxonomy-{taxonomy}.php doesn’t show my posts
- Show products as posts on archive page
- Pagination not working past page 3 on archive page of category
- My archives page won’t sort posts by month
- Change Title Based on Taxonomy Filter in archive-{cpt}.php
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- I want to display all related posts for a selected tag in WordPress
- next and previous category name and link parent only wordpress in archive page
- get first limited words from a custom post in the archive page
- How do I apply a wordpress function to something with no ID inside an archive page?
- How to display archive by selecting year and then selecting month
- Custom taxonomy return 404
- Show index and not the archive for “Dog Custom Post” with default slug
- Custom post type archive page not showing on archive-posttype.php
- Custom post type with two templates
- Custom Post Type Archive – archive.php is present, but it is not being used
- Multiple archives for cpt, taxonomies, terms
- Making a archive gallery page for a custom post type which already has an archive page
- Get meta value when the page is a blog archive
- Modify category archive page loop on functions.php
- Permalink Rewrite with Archive – Archive gets 404
- How to Add Wrapper to Infinite Scroll Javascript?
- Archive templates based on taxonomies
- Organizing Custom Post Type Archive Template
- listing custom post type category page
- Categories to A News Page
- Two different archive pages showing the same content
- Using post type archive page for taxonomy archive
- Archive custom template from search
- how to pass args for archive.php query?
- Create a custom page URL
- IF taxonomy archive is hierarchical THEN
- Limitless amount of posts in custom archive page
- Duplicating wordpress install issue
- Add custom display condition to Elementor Theme Builder for custom taxonomy children, grandchildren, and great-grandchildren
- WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query