Copied from StackOverflow:
WP_Query
offers adate_query
parameter, 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
- Query Custom Post Types on Available Dates
- custom taxonomy and custom post type url conflict
- greatest() function returns undefined property
- How use %like% in sql statement wordpress
- Custom query shows custom post types in trash
- Multiple post type queries (with specific arguments for each)
- wordpress reusable content blocks
- Override plugin with functions.php
- medoo framework in WP plugin
- WordPress logo upload option in theme panel
- Accessing GET variable named ‘error’
- Should i delete the posts created by a plugin on uninstall?
- Allow users mark posts as “complete”?
- WP_Query ordering numbers as letters
- FacetWP group listings by custom field [closed]
- Can’t get order_by meta_value_num to work properly
- Is there a way to order posts and custom post types as one group?
- RW Meta Box ,Problem setting post title
- How can i list random post from multiple category?
- How does WP handle multiple matching rewrite rules?
- Sorting multiple custom post types without a meta key/value pair by sort order
- Saving Custom Post types and fields to a custom table
- dynamically generating plugin syntax
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- Building a store locator with google maps
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- WooCommerce shop page orderby [closed]
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Call to a member function have_posts() on a non-object on normal loop
- Get posts from WP_Query and format them on admin_head
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Not getting author rank when using return
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- Correct way to make meta box with more than one meta field secure
- I want to extend the current themes’ single.php to display the meta fields of my CPT
- How to query the custom fields by language?
- Plugin custom post type – Internal server Error
- Exclude post by custom meta with pre_get_posts
- How can I create a custom shortcode that will return a custom post type by ID?
- How do I “get the next 10 posts after post_id == x”?
- Is it possible to create Custom Post plug-in?
- get_post_type() and WP_QUERY issue
- Get latest 3 posts from multiple CPT in one query
- switched from query_posts to WP_query, not working now?
- get_post_type on post.php
- AJAX search posts and pages
- List taxonomy terms for post as checkboxes
- All of my custom posttypes are 404’ing
- more types plugin – display all post of post type on page
- When using Simple Fields plugin, how do I pull the information out of the database to display on a page?
- Multiple instances of nivo slider plugin
- How to make a proper custom post type link
- DROP TABLE with uninstall hook not working
- Matching Chapters to a Custom posts [closed]
- 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
- ‘No Results Found’ on single post for custom post type
- Keep a post copy when this one is updated – issue
- Making a Template for a CPT created by a plugin
- How to change this WP_Query to get all ProductIDs and not only specific one?
- how to add a button next to the wordpress view button?
- auto populate list of questions if user select a category xyz
- How to call WordPress function other files
- Polylang non-default language ignores tags in WP_Query
- Insert content of a post into another
- WP_Query and NULL meta keys
- how to use in custom single.php template using php?
- WordPress page and plugin list using sql query
- Mq translate plugin custom post type issue
- How to create a custom shortcode based on the layout?
- Using AJAX to generate front end / viewer end pages
- Different Ways to Query Custom Post Types?
- “Custom Post Type Permalinks” plugin URL strcuture
- Unable to delete custom post types, confusion around capabilities
- background images WP Supersized on homepage
- pagination not working for category.php (custom post types in categories)
- Adding CSS to custom post type admin page causes error
- Trending Tags based on post views
- Shortcode in a blog post, footer and related products stop working
- Plugin does not create a custom table upon activation
- How to delete only user meta value (not key) from usermeta table in wordpress?
- WordPress custom post type
- How can i see/log all requests coming from a registration form (not from the UI)?
- display news with pictures 3 small and one large (loop)
- Calling an custom field from theme option at the frontend