Got the idea from this post to change my query : How to “orderby” the first array in a meta_query that uses multiply keys?
I moved the state query into the larger array of queries, freeing the ‘meta_key’ value to be assigned to event date
$args = array(
'post_type' => 'tf_events',
'meta_query' => array( $relation, $date_query, $date_query2, $state_query ),
'posts_per_page' => $limit,
'meta_key' => 'tf_events_startdate',
'tax_query' => array( 'relation' => 'AND', $type_query, $host_query ),
'order' => 'ASC'
);
add_filter( 'posts_orderby', 'my_posts_orderby_date', 10, 2 );
function my_posts_orderby_date( $orderby, $query ) {
global $wpdb;
return " CAST( $wpdb->postmeta.meta_value AS DATE ) " . $query->get( 'order' );
}
Related Posts:
- Excluding posts by meta, and also keeping posts without the meta
- Customising the default wordpress search functionality
- How to hook a filter to catch get_post_meta when alternate a custom field output?
- How to use update_{$meta_type}_metadata filter to modify meta value
- What is the most efficient way of querying posts based on visits and date for current day?
- How can I display image metadata?
- Where is the proper place to add a filter for pre_get_table_charset?
- WPDB Multiple site’s posts and get featured images
- Possible to filter the posts or categories that XML-RPC users see in their mobile application?
- How to filter into post meta data before saving
- Filter custom post types in archive
- Explanation for remove_filter used in the below code [closed]
- Filter list by a unique meta value dilemma
- How to remove get_post_metadata using remove_filter inside a class?
- Sorting and limitation with pre_get_posts
- Filter Posts by current Month
- Get .subsubsub count of post per status queried using pre_get_posts
- Custom wp_query time filter on meta_value
- Is it possible to apply filter to meta key value when querying posts?
- Run posts_where and posts_join only on the main query
- WordPress query posts with multiple post_meta data
- Filter for author list in gutenberg core editor
- Filter posts by meta data using custom query
- Want to use wp_get_current_user() in query filter
- Filter authors on meta value
- WP_Query filter by custom meta
- List all categories that have results in a query
- Display posts from today and future in Elementor ‘posts widget’
- Having issue with dynamic data within restrict_manage_posts function
- Displaying posts on a page that have been assigned a value in a database
- Add option to query string before get_posts() is called on archive.php
- Filter on the day of the week from timestamp
- Admin view: filter posts by whether they have specific taxonomy attached
- Use $wpdb->get_results with filter based on array
- Restrict access to custom post type and filter from every query
- How to add more than one custom metadata as filter on the post list page?
- Hide H1 Title using the_title filter
- Retrieve post data via WPDB class
- How to create a list of terms who’s posts also have a predefined external term?
- Query Multiple Filters, one with Meta
- what is __return_false in filters
- Custom theme hooks / filters – passing arguments
- What params are available with the_content filter?
- How to hook wp_list_pages?
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- apply_filters(‘the_content’, $content) alternative
- How to make an activities stream mixing posts and comments?
- Changing document title only on a custom page template
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- Hook different functions to the same filter conditionally OR Pass additional arguments to existing filter?
- How do I pass the value from a foreach loop to an add_filter function? [closed]
- Search results sorted by post types
- Pass parameter to the upload_dir filter
- Filter or Hook to catch pre-rendering of post content
- Only display posts after current date
- check to see if hook is available
- Filter users by custom colum not meta key
- Echo a hierarchical list of post data from custom fields
- How to allow users to view pending posts of a specific custom post type?
- Remove filter callback: method in class
- How to execute a SQL-query which contains multiple queries using $wpdb->query?
- How to filter meta_values using REST API
- How do I use remove_action on an add_action that uses an array?
- Change the default 10-day expiration for the password protected pages cookie
- Add content as soon starts
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- Set Condition echo function get_post_meta
- Access get_the_title() from ‘excerpt_length’ filter
- Wrong post_status notice after wp_insert_post_data
- Comment search plugin
- wpdb query problem to access previous 3 days posts
- How to display the content HTML of a page without displaying the gallery code as well
- Apply filters with multiple filters
- Remove Comment Author Link only for subscribers
- WooCommerce coupon hook argument NULL when using filter woocommerce_get_shop_coupon_data
- How can I edit comment meta value before it is saved?
- Why current_user_can(‘edit_comment’) always true?
- Redirect after post deleted
- WordPress Mysql query and Duplicate
- How to stop filter from running on the index.php page?
- Filter Shortcodes when using get_page
- Filter Media by attached page or blog post in Library
- How to stop DOMDocument destroying embeds?
- Run `wp_insert_post_data` on all posts
- How can I pass instance via apply_filters as a parameter?
- WordPress add_filter to post_date
- create a shortcode with acf including a filter
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- Apply a filter str_replace on specific caracters array in the_content()
- Put data in my-account/view-order/id/ page
- The title of an attachment is not working
- Add Default WordPress Formatting To Data From External SQL Tables?
- Cache metadata for set of posts
- Joining tables not working in the post editor page
- Auto append text after the title?
- add_filter(‘the_content’, ‘method’) does not trigger my custom method
- Replacing text using add_filter
- Background color and background image below element in Contact Form 7 – error tip [closed]
- Change password reqts with NO plugin without breaking resetpass link?