I have solved my problem and it had nothing to do with the query, the database or the post type.
The problem was that in trying to initially construct the query I had left a pre_get_posts function in my functions.php which was conflicting with my query. The lesson here for me is to make sure I have thoroughly checked ALL files.
The offending counter code:
// Events Pre Get Posts
function my_pre_get_posts( $query )
{
// validate
if( is_admin() )
{
return $query;
}
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'events' )
{
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'event_date');
$query->set('order', 'DESC');
}
// always return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
Related Posts:
- Select All in Parent Category, Group by Child Category?
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- WP_Query post at custom position
- query order by date on custom type: wrong order
- Re-order posts in query after
- How to query different post types in specific order?
- Combining sorted and random CPT
- Previous/Next Link by Meta Value in CPT
- Wp_query: sort by PHP variable
- How to do WP_Query with two meta fields with orderby clause
- Order Custom Post Type by Custom Field Value
- Change sort order when using ‘orderby’ => ‘type’
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- WP_Query of custom post type sorted by meta_key has unexpected results
- WP_Query not resetting after wp_reset_postdata
- Post ordering not working with custom field
- Displaying Portfolio Filter by Category Order (alphabetically)
- Display Parent-Child Posts in specific order by comparing IDs in array
- Query to show post current day
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- SEARCH QUERIES – REVERSE OUTPUT
- Wp Query sort order from custom MetaBox
- Using Orderby and meta_value to order natural/alphanumerical
- WP Query with multiple post types ordered by custom meta date then published date
- Orderby modified only for specific post types
- Custom post order when using OR relation
- 404 on Pages for Custom Post Type & Query_Posts
- WP_query orderby not working after WP4.0 update [closed]
- Query order by meta value force specific tag first
- Order Wp Query by earliest of 3 dates meta query
- Query multiple post types – Order by type and post title title
- Custom post ui plugin & WP_Query – Polylang
- How to orderby multiple meta fields if some fields are empty
- How can I get the number of custom post type posts that have a specific attachment image set?
- How to use load more custom post type data normal or according to on click category tab In WP
- orderby rand is not working for a custom post types
- Sort CPT archive by order prevents sorting in admin
- Problem querying Custom post type by custom fields
- How do I set default meta value by post type?
- Orderby CPT custom fields not working
- Custom taxonomy rewrite give pagination 404
- WP_Query order by custom field, then randomly order some of results
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Mixing 2 custom post types with posts output in specific pattern
- Custom post taxonomies as tax_query terms?
- creat filter with wp_query
- Troubles with acf/save_post and WP_Query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- Query custom post type with ACF Date
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- Custom WP Query on custom meta and sort by multiple meta keys value
- Show only one post on custom post type archive
- Woocommerce search pagination not working
- How to order WP_Query by parent for hierarchical Custom Post Type?
- Including metaboxes from custom post types in global search — continued
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How can I made custom taxonomies relationship?
- Query Multiple Custom Posts by Custom Fields
- What’s the WP way to load remaining custom posts?
- Why is this query not working? (Standard posts + custom post type)
- How do you paginate a query grouped by month?
- Custom taxonomies relationship
- Get Posts by multiple custom fields is not working
- Custom post type ‘articles’ ignores posts_per_page, reserved post_type?
- Several post types on WP Query by tag and taxonomy
- WP Query with categories only shows one post and ignores the category
- Polylang non-default language ignores tags in WP_Query
- WordPress request fiter order by related post’s post_title
- How to order and group custom post type posts by year and month
- Custom Widget WP_Query problem
- Custom query at top of archive search page, arguments are overridden
- WP_Query custom post type query not showing the exact post type
- How to display post list inside post
- Pagination issue on category.php using custom post type query
- How to have this permalink structure: post_type/postname/custom_inner_page
- Problem: wp_query outputs all images on site
- Query Custom Post Type Taxonomy term with multiple parameters
- Sort entries by date mixing two post types
- Why is my category template ignoring post type?
- First custom field value (out of several) displayed twice after query
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- Prioritize posts in query by meta keys?
- Get the taxonomy of a post hierarchically
- Display Woocommerce Orders for specific author [closed]
- Add Custom Post Type of specific Custom Taxonomy to regularly blog loop
- How to get all tags of a custom post type by id
- Filter Posts from the Main Query
- WP_Query orderby and tax_query
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Different Ways to Query Custom Post Types?
- Ordering custom post type by multiple custom fields
- Order posts by 2 custom fields and if one custom field is zero orderby another custom field
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- Possible to filter custom post type with multiple meta data?
- can these 3 queries be re-written as 1 query?
- Advanced search form with filters for custom taxonomies
- Manage Columns : order by post_parent’s title
- Order by custom field meta_key date and then by custom file meta_key number