Here’s a plan:
- Store the dates as individual custom fields with the same meta_key (ex: start_date)
- JOIN the wp_posts table with the wp_postmeta table, without a GROUP BY (to allow the same event to appear more than once)
- ORDER BY start_date
The full query would look like this:
SELECT wp_posts.*, meta_value AS start_date
FROM wp_posts INNER JOIN wp_postmeta ON (ID = post_ID)
WHERE post_type="event"
AND post_status="publish"
AND meta_key = 'start_date'
ORDER BY start_date
PS: This requires you store the date in YYYY-MM-DD format, which you should do anyway, for compatibility with mysql2date() etc.
Related Posts:
- Custom Post Type ‘Event’: Chronological list of recurring events from meta_values in array
- How to Get All Posts with any post status?
- How can i get count from query post
- query_post by title?
- How to set a custom post type to have viewable future posts
- WP_query parameters for date range
- Custom post type archive 404’s with paginate_links
- How to set posts per page using WP_Query()
- query_posts() in function makes global $wp_query out of sync?
- Problem with ‘post__not_in’
- Display Custom Post Type Fields
- Sort posts alphabetically by custom field value, insert divider between different letters
- Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?
- Loading Custom Post Type Events into jQuery-based FullCalendar?
- Retrieving 3 latest post from each of 5 different custom post types
- how to group custom post type posts by custom taxonomy terms
- Using Query Posts With Multiple Post Types And A Taxonomy
- How to get the parent’s taxonomy?
- Total Count of Posts NOT in Selected Categories?
- Query not returning CPT posts
- Unable to display multiple post types in same query (WPML WP_Query)
- Query for posts in 2 taxonomies
- Quickest way to get last or oldest post date – WP Query
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Custom query shows custom post types in trash
- Multiple post type queries (with specific arguments for each)
- Order posts using a custom array
- Sorting multiple custom post types without a meta key/value pair by sort order
- Tricky WP Query
- WordPress pagination showing same posts on each page
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Get latest 3 posts from multiple CPT in one query
- Display upcoming Events for next 7 Days
- Search breaks when querying main loop for category
- Using ajax with paging and a custom sub-query
- Polylang non-default language ignores tags in WP_Query
- Different Ways to Query Custom Post Types?
- Custom loops, sticky posts, and pagination nightmare
- pagination not working for category.php (custom post types in categories)
- How to display Related Posts based on number of taxonomy terms matched
- ACF: post query, hide duplicate values [closed]
- How to make WP_Query not to show irrelevant posts?
- Loop for custom post types filtered by a taxonomy
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Pagination not working on custom query on a page
- find custom post type post by searching its custom field with my string
- FacetWP paging custom wp_query
- Can’t change posts per page in WordPress Post Type Query
- postsperpage value not being applied
- how to compare different timestamps in wp-query for events custom post types?
- Custom Post Type Query W/Category Dropdown
- odd behaviours from template tags
- Having an issue doing a WP_Query with post_content and category__and
- Custom query looking at multiple custom fields and properly sorting
- Pre-existing arguments when using queries
- Find Posts based on Child Post value
- Sorting the Loop by Taxonomy Value
- Custom Query: Multiple CPTs and a taxonomy filter
- WP query_posts group by meta field related
- Custom wp-query display post only today
- custom post type and a “sticky” position taxonomy
- Use WP_query to match post types based on custom field values
- Ordering of posts, 2020 Year showing as next event when should be last
- minimize wp_query call to database
- Query the title of the page to show posts with matching category in the loop
- Main site single-property.php design, as homepage of a multisite
- Query events post type after current date and timezone
- Imported Content Doesnt Show Up On Frontend
- WordPress custom post type
- display news with pictures 3 small and one large (loop)
- Query Event Posts by Date
- Custom Query With Multiple Meta Key Value
- Custom post type blog pagination conflict
- Query Posts From Multiple Post Types
- send user to first page of results when reposting to page?
- Count of posts with meta_key filled in?
- How to refine WP-Query with further criteria
- Run second query on page based on author of the first query
- Query Posts (post meta)
- How do I correctly query posts from a post ID?
- How to exclude certain portfolios from a loop
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- Display ACF object field data using Elementor Custom Query
- Assign a tag to custom post type using a query
- How do I exclude the current post from the upcoming post query
- Querying posts from multiple sites in a network?
- Custom query form submission pagination
- Paginated Taxonomy Term Archive including one post per term
- wp_query to find posts by year and month
- How to query a custom post type with a taxonomy filter but display post type archive page?
- Custom WP Query on custom meta and sort by multiple meta keys value
- How to get all post except particular category without breaking the paging
- How do I rewrite this loop as a new WP_Query style-loop?
- How exclude 3 latest posts of a category in query_posts
- filter posts by meta key with pagination
- Help with query_posts function
- Manipulate query to show specific post
- Load posts via AJAX without draft status