Copied from StackOverflow:
WP_Queryoffers adate_queryparameter, allowing you to set a range with before and after.https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
$args = array(
'date_query' => array(
array(
'after' => 'January 1st, 2015',
'before' => 'December 31st, 2015',
'inclusive' => true,
),
),
);
$query = new WP_Query( $args );
See the linked documentation for more details.
Note that the other answer, which uses a postmeta query, is really out of date, no one should do that now that WP_Query supports these date queries.
Related Posts:
- ACF: post query, hide duplicate values [closed]
- how do i remove posts from a WP_Query so the pagination is right?
- Accessing post’s meta data based on user’s click of a post
- Redirect to another page using contact form 7? [closed]
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- How to search post titles with whole words only, but not the exact word only?
- custom post type get_posts() function not work
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- WP-Snap too slow (caused by WP_Query?)
- Insert data in custom table during new post creation
- Making a Custom Post Type Publish Loop
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- Creating a default Custom Post Template that a Theme can override
- Getting Custom Post Type content from main-site of a Multisite
- Custom comment type maybe?
- Using Query Posts With Multiple Post Types And A Taxonomy
- Twillio How To Send SMS for Custom Post Type
- Find out if request is for custom post type archive before query runs
- Seriously stuck with some custom meta box/plugin stuff
- Enable comments for post with comments meta box removed
- How to Build a Movie Library in WordPress 3.x
- Quickest way to get last or oldest post date – WP Query
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- How to get images from EDD post?
- medoo framework in WP plugin
- Accessing GET variable named ‘error’
- Allow users mark posts as “complete”?
- Is there a way to order posts and custom post types as one group?
- How can i list random post from multiple category?
- dynamically generating plugin syntax
- get_post_type() and WP_QUERY issue
- AJAX search posts and pages
- Custom post type – no layout section of Document tab, and no author choice
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Keep a post copy when this one is updated – issue
- how to add a button next to the wordpress view button?
- How to create a custom shortcode based on the layout?
- pagination not working for category.php (custom post types in categories)
- Adding CSS to custom post type admin page causes error
- How to get a list of bundled products using wp_query in woocommerce
- WordPress Apply filter in plugin causes 500 internal error
- Meta query for comparing two dates
- Amazon.com intergration with WordPress?
- Sticky option for custom post types without using custom fields or plugins
- Adding custom meta boxes to specified custom post type
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- How can I store data from custom fields to custom tables?
- 2 wordpress site same database
- How to Include Custom Post Content From Plugin
- Custom post type change excerpt more and excerpt length
- What hook can I use to modify custom post data before it is displayed on the page?
- Delete data from custom table when deleting a post
- Order posts of a custom post type by the event date using FT Calendar Plugin
- hardcoded wp pages/plugins problems
- How display specific category post to specific users?
- Sorting the Loop by Taxonomy Value
- Searching a tab/space delimited text file based upon form criteria and returning a ‘record’ into a word press results page
- Custom Query: Multiple CPTs and a taxonomy filter
- Custom wp-query display post only today
- Need to edit author permissions | custom taxonomy
- Is it possible to pin a post in second position from top
- Save log for imports in WordPress database – options-table, custom post type or other place?
- Error in Fetching Custom Post Type parent Category URL (slug)
- Register PODS Custom Field with WPGraphQL [closed]
- Hidden permalink different from displayed permalink
- Adding custom post category to categories widget
- Custom Post Type with Sequence ID
- How to arrange custom posts in the backend/admin by custom taxonomy
- Adding LOAD MORE on a page
- adding dynamic/multiple slug values in ‘option_none_value’
- how to convert frontpage.php to dynamic page?
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- Only return taxonomies that are linked to a category & product
- How to add specific posts to specific pages in WordPress?
- User Following System
- ACF Query result in a new td (echo)
- Multiple Meta key in search
- wp_schedule_event function reference
- Imported Content Doesnt Show Up On Frontend
- how to repeat taxonomy in different places on wordpress
- Loop carousel slider in wordpress
- display news with pictures 3 small and one large (loop)
- Displaying image from a repeatable group
- CPT-onomies CPT_TAXONOMY->get_terms extremely slow with 6K posts
- Second foreach loop breaking (Posts2Posts)
- Ger posts from similar tags and categories
- wp_query for more fields plugin
- single.php fires more than once after clicking on any post to view with different post id each time
- How to list the categories by custom taxonomy created?
- How to laod wp_enqueue_style to another header i created my self
- Looking for a plugins for organization portal (Staff, Units, Departments)? [closed]
- Browser Cache causes ‘Orderby=rand’ to return the same posts
- Assign a tag to custom post type using a query
- Wrong block appender button showing
- Select posts from list and add them in a new list
- jet engine listing for every single taxonomy in post type [closed]
- Failed to update a post when I add a taxonomy to it
- How to add CPT in Elementor pro search template
- Show the author only own types of publications. (JetEngine, Elementor)
- How to check if the post exists in any of the categories?