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
- Tips for using WordPress as a CMS? [closed]
- Custom Post Type Templates from Plugin Folder?
- How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
- WP JSON REST API (Ryan McCue) how to query posts with specific meta data with ‘AND’ relation?
- Creating two database tables via plugin
- Query Posts by Custom Field ‘Price’
- Custom Post Type “Event”: chronological list of recurring events
- Date query for a custom meta field
- Comparisson between date() and a date from wp_postmeta
- How to extract images of post and pages excluding header and logo image in wordpress?
- remove custom taxonomy metabox form custom post type
- Used with meta_query in query_posts works slowly
- Custom Post Type Statuses
- Query for posts in 2 taxonomies
- add_meta_box Callback not being called
- Star rating for custom post types [closed]
- How to Make a Custom Grid View
- Get image URL from media library in input
- Way to hook into a sidebar call to replace it with a custom sidebar
- How use %like% in sql statement wordpress
- FacetWP group listings by custom field [closed]
- Get posts from WP_Query and format them on admin_head
- Plugin custom post type – Internal server Error
- Is it possible to create Custom Post plug-in?
- switched from query_posts to WP_query, not working now?
- When using Simple Fields plugin, how do I pull the information out of the database to display on a page?
- How to make a proper custom post type link
- Matching Chapters to a Custom posts [closed]
- How to change this WP_Query to get all ProductIDs and not only specific one?
- Insert content of a post into another
- how to use in custom single.php template using php?
- Mq translate plugin custom post type issue
- Different Ways to Query Custom Post Types?
- background images WP Supersized on homepage
- What is the best way for showing a grid of customer logos?
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- How to make WP_Query not to show irrelevant posts?
- Loop for custom post types filtered by a taxonomy
- How to set category correctly for a custom post created by a remote API call?
- How to use template_include hook with form submission?
- find custom post type post by searching its custom field with my string
- FacetWP paging custom wp_query
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- Can’t change posts per page in WordPress Post Type Query
- Price comparison table based on Custom Post Type?
- How can I list custom post type categories of portfolio
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- “Allowed memory size” problem [closed]
- “After file loaded” action
- Custom Post Type Query W/Category Dropdown
- Custom Post Type, Custom Columns List
- Adding CASE in WP_Query
- How to create repeater field manually, without plugin (ACF Pro)?
- how to create hierachial taxonomy and manage under single post type?
- need click to clipboard button on my site
- Trying to get property ‘ID’ of non-object in /wp-includes/class-wp-query.php on line 4044
- Setting Author on CPT
- Check if theme supports sidebar
- Custom Post Type same name as Category
- how to display recent post by category on home page
- Adding category base to url in custom post giving 404?
- How to display the custom post related blog by category?
- Undefined index: custom_post_template_present
- any word search WordPress
- Warning: call_user_func_array() problem can anyone help with it?
- Problem with checked box on wp car manager plugin
- How to fix slow comment query?
- How to insert variable which contain array value in wp_options table?
- Trending Tags based on post views
- WordPress custom post type
- Array to string conversion error when trying to POST multidimensional array
- Creating themes using the one Plugin (Toolkit)
- How to add jquery to my custom post type wp plugin
- WordPress list child pages of custom post type
- Custom Query With Multiple Meta Key Value
- making a glossary with wordpress
- Create custom fields on a post
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- How to exclude certain portfolios from a loop
- Change the behaviour of archive cpt category and single cpt by plugin, not by theme
- A plugin for software reviews site like this one?
- Display Custom Post Type and Custom Taxonomy Data on Front End Using Only a Plugin
- WordPress show different custom post type
- Filter custom post type returned from REST api
- 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
- Failed to update a post when I add a taxonomy to it
- How do I exclude the current post from the upcoming post query