Saving the date in post meta is a slightly more sane approach, the post_date
column was not designed with your use case in mind. You may get weird results with dates before the Unix epoch (January 1, 1970). Then it’s just a simple meta_query
to load posts between dates, no filter necessary.
$start="1900-01-01";
$end = '1949-12-31';
$args = array(
'post_type' => 'events',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => '_event_date',
'meta_query' => array(
array(
'key' => '_event_date',
'value' => array( $start, $end ),
'compare' => 'BETWEEN',
'type' => 'DATE'
)
)
);
$events_query = new WP_query( $args );
Related Posts:
- Custom Post Type Archives by Year & Month?
- Page Template as Custom Post Type Archive
- Assign Page Template Within A Custom Post Type
- Posts per Page on custom Taxonomy Template
- Custom Post Type – Archive page title
- Multiple templates for custom post type
- query_posts with a custom post type, a meta_query and sorting by post date?
- Editable content on a Custom Archive page
- Page template with different page and post content
- How to integrate single and archive templates for custom post type in any WordPress theme
- WordPress Page hierarchy ( parent is singular of custom post types slug ) is returning not found
- Posts per Page on custom Taxonomy Template
- Want to display my custom date archive to date.php but dont know how
- How do I get the posts from single page custom post type from a sidebar to display in a page?
- Show index and not the archive for “Dog Custom Post” with default slug
- Templates list in “Page Attributes” metabox is inaccurate
- Different Ways to Query Custom Post Types?
- Custom Post Type Template Alternative
- General advice on addressing content-centric pages
- BBPress Search results in WordPress search
- Custom post type archive page for multiple post types
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Fields for different parts of a page
- next_/previous_post_link() `in_same_category` appears to fail when true
- Multiple templates for single custom post type
- Order post by date with ACF
- Listing all term items alphabetically / sorting loop
- How do you create a custom template to display a category with an image and related posts below?
- WordPress Custom Search by post_type
- Paginate_links in custom post type template
- pagination not working for category.php (custom post types in categories)
- How to display Related Posts based on number of taxonomy terms matched
- Pages Become “Archive” Instead of Using Page Template
- My archive-posttype.php template is not loading
- Custom Post Archive is not working
- How can I set the page template of a new custom post type post?
- Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters
- Custom post type archive with page as parent url
- Add parent post to Custom Post Type [closed]
- Set featured image to archive.php
- Custom post type pages return 404 page?
- Filter date from post meta when date is in string format
- query_posts adding extra code to homepage
- How to show only the most recent post on my custom post type archive?
- Multiple single templates?
- How to make WP_Query not to show irrelevant posts?
- What is the ID parameter for custom post types in query_posts?
- Loop for custom post types filtered by a taxonomy
- What’s the name of the custom post type yearly archive template?
- Custom post type, global categories — what’s the template name?
- Custom URL redirect in WP
- WordPress Picks Up Wrong Template for Custom Post Type Archive Page
- How to hyperlink content from archive page with custom post-type
- Associate page w/ specific single post template?
- How to limit post per page of custom post type?
- Set thumbnail and title for a post type archive (not post itself!)
- How to set up Custom Post Type archive page as Front page
- Url to archive page for custom post type
- How can I use archive-{post_type}.php theme template?
- How to display CPT archives?
- Custom query – get_the_terms not work
- Custom meta Title for custom post type archive from page
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- Include php on a specific page template
- Return the name of the post type
- get comments by current user inside page template
- page template for custom post type
- 3 random images from custom post type, each in a div with a diffrent class
- Page Template Dropdown For Custom Post Types
- Why are some of my custom posts not showing up on my page?
- post-per-page and offset not working
- Control content before and after custom post type loop
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Display custom posts randomly in custom taxonomy archive
- Getting all ID’s matching a title in a custom post type
- current-menu-item not added on page showing custom post type (rendered with archive template)
- why is the current page title being output?
- Count custom post type based on two meta data
- Alphabetically sort a taxonomy.php template by post title
- Querying multiple values from a single key
- Not able to export large no. of posts in csv
- attach CPT data to a taxonomy
- Custom Permalinks For CPT and pages with parent. Advanced WordPress
- Permalink problems with custom post type and custom taxonomy
- Pagination not working on custom query on a page
- Loop through posts of only 2 statuses
- Targeting custom post type via functions.php doesn’t work
- sort CPT on Custom Taxonomy Archive page
- find custom post type post by searching its custom field with my string
- FacetWP paging custom wp_query
- Sort custom post type by most current date picker
- I am trying to get cutom post cout by month of current taxonmy term
- ACF for custom post type archive pages: which hook to use?
- Use the custom post type archive for taxonomies?
- providing access to post_id or post inside functions.php
- wp_get_canonical_url showing first url of the post for custom page
- Custom page for editing custom post type on frontend based on url
- Custom Post type date archive for custom taxonomy
- Show categories of custom post type and not all posts