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
- How to remove custom post type archive
- How to use a custom post type archive as front page?
- Get the ID of the latest post
- Add Content to Page without shortcodes
- Proper way of making custom post type landing page or archive page
- Custom Post Type Archives with 0 Posts Redirects as 404
- Display Custom Post Type Fields
- Get monthly archives for custom post type
- How to get_queried_object on multiple objects?
- Post type archive page not working
- Page Templates – this code only works for one Custom Post Type
- How to get the parent’s taxonomy?
- ascending order custom post type
- Getting taxonomy terms used by custom post type
- Archive or taxonomy pages not working for custom post type
- How to get only one category of custom post type?
- Custom Post Types – How to include custom fields
- How to list custom post types?
- get_queried_object error How to show post count by month in the taxonomy page
- List custom post type by custom tax term as page title
- Custom Post Type Events Archive Grouped By Month
- After updating a page, all pages on the site used the index.php template
- Page Templates Drop Down Select for Custom Post Types
- Display only post types that are direct children of the current taxonomy
- Using custom page templates with plugin [duplicate]
- Custom post type search with slug in URL
- How can I give CPT archive correct body class?
- Custom post type is showing custom home page, not archive page
- How to query_post custom posts within default taxonomy?
- URL of a custom post type’s post format archive?
- Create template for taxonomy results limited by Custom Post Type
- Query Custom posts of same taxonomy as the post itself
- How to use has_archive but disable feed per post type?
- Custom post type: Disable single page, but keep archive
- Post count by month of taxonmy term
- Category with post type pagination returns 404
- Custom Post Type has_archive
- list archives per post types
- Adding the_content() in custom template email
- Display a custom posts page for post type
- Is it possible to have a custom post type with feed but without the archive?
- Listing all term items alphabetically / sorting loop
- My archive-posttype.php template is not loading
- Add parent post to Custom Post Type [closed]
- How to make WP_Query not to show irrelevant posts?
- What is the ID parameter for custom post types in query_posts?
- What’s the name of the custom post type yearly archive template?
- How to display CPT archives?
- current-menu-item not added on page showing custom post type (rendered with archive template)
- Use the custom post type archive for taxonomies?
- How to get the current category with custom posts
- List all posts in taxonomy term
- Custom Post Type Specific Post Template
- Custom post type category permalinks and archive pages
- Custom Post Type Query W/Category Dropdown
- Query all posts under one taxonomy? Why is my code not working?
- CPT archive with WP native/core tax/categories
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- How to add specific terms in a custom post type?
- Limit custom post type to the authors only on front-end!
- get_queried_object not work in taxonomy page
- Custom post type not pulling CSS
- How to manage a custom post type archive as a page?
- Custom post types not displaying per category
- Custom post type with two templates
- Get month and day from a Date Picker custom field
- custom fields not showing before get_header
- WordPress custom post type
- WordPress custom post type queries
- Custom Post Type Pagination Not Working or Single Posts Displaying?
- Change custom post status to draft before today
- Query Distinct Taxonomies of Custom Post Type
- Custom post type category page not working
- paging is not working properly on news archives page [duplicate]
- Modifying and Displaying URL’s in a Post Template using parse_url
- CPT Archive with parent page
- How to save an integer as taxonomy term?
- custom post type not getting archived?
- Remove plugin’s custom post type archive page and single pages [closed]
- Inserting two categories
- How to exclude certain portfolios from a loop
- Adding custom theme template to custom post type [duplicate]
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- display related posts based on the PAGE TITLE