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
- Exclude a category from WP_Query
- “pagination” (but not really) and queries using custom posts types
- Pre_get_posts Gives 404 on Custom Post Type
- Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)
- Query for posts from any post type but only add instock products
- Query not returning CPT posts
- Custom Taxonomy and tax_query Issue?
- WooCommerce – Show orders for a specific product ? [closed]
- WP_Query with custom post_type and cat retrieving unwanted posts with the custom posts
- Query to get the author who having maximum number of post (custom post type)
- Pagination not working
- Select menu should display categories and the item’s depth
- Custom Post Order for a Custom Post Type
- Show Post Count of a Category
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Filtering by Post Meta Custom Fields – Performance
- WP Query—Relationship between two custom post types and their fields
- Unable to get paginate_links working with a custom query [duplicate]
- Setting proper query for multiple custom admin filters
- Query custom post type with tags
- Custom loop with multiple taxonomy queries
- Custom taxonomy rewrite give pagination 404
- WP_Query order by custom field, then randomly order some of results
- Custom query at top of archive search page, arguments are overridden
- How to display post list inside post
- Advanced search form with filters for custom taxonomies
- Showing specific post in order of array wp_query
- WP the_posts() on single-cars.php get category link
- tax_query not working in template
- Custom Taxonomy Not Showing in Front-End When Outputting a Custom Post Type with WP_Query()
- Custom WP_Query always respond with 200 status even when no entry
- Pagination 404 on Index with custom query
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Trying to add a class to post links
- Custom Post Type Archive Pagination
- Two queries – one with checkbox ticked, one without – comparing meta_query
- Custom post type pagination error
- WP query_posts group by meta field related
- posts_per_page in custom WP_Query does not override “Reading” settings?
- Apply category query clause to posts of custom type
- custom post type and a “sticky” position taxonomy
- WP_query has incorrect wp_posts.post_name = ‘asc’ when I have custom post type called ‘order’
- WP_Query to display number of custom post type filtered (order by) taxonomy
- 2 modal windows with ACF content on Archive page
- post_type incorrect for custom post type
- Live search by custom tag
- Custom Post Type – Display all, wrap in groups of 3
- How to order multiple custom post types with same taxonomy by date
- Staggering featured post using ‘sticky’
- Ajax load more inside custom post type taxonomy
- How to get the posts that my following users are liked?
- Only show categories that have posts within custom post type
- Create a custom wp_query from a specific custom post type with specific taxonomy
- Display all Custom taxonomy terms and their relevant custom posts
- Query breaking with ‘posts_per_page’ => -1
- How To Loop Through list with Custom Post Types
- CPT or Custom Table for Repository of Serial Numbers
- Query Pulling the same post twice
- Use Tags to Query Associated Multiple Posts and Get The Average Of Custom Field Values
- Custom Post Type + Category archive
- Pop up showing same content on all posts display.
- Custom post-type’s pagination not working in category.php
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Querying meta values within an array
- Count of posts with meta_key filled in?
- Filter Custom post type by another Custom post type
- Are custom posts included when getting a categories’ posts?
- Display ACF object field data using Elementor Custom Query
- Sort ACF by custom taxonomy