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
- How to use parse_query() to add an additional filter based on content to page search?
- WordPress Gutenberg core/heading block (wp-block-heading)
- How to insert a value to decimal type field using wpdb->prepare?
- How to redirect a unique link based on login status
- add_filter( ‘the_title’ gets through this if statement twice
- Changing the category for existing Gutenberg blocks
- Does this archive template part look like its making too many calls to the db?
- Filter Post Title without affecting screen-reader-text
- How to modify image caption in posts?
- Extend Nonce Lifetime for Specific Nonce Creation
- Custom sort orderby question
- get_post() with filters applied
- Hook to change the site URL
- How can I tranlslate post date in italian?
- Run `wp_insert_post_data` on all posts
- Insert NULL value using prepare()
- Replace a specific URL on all apperances on the Website (Maybe a filter?)
- Use alternative front page if cookie is set
- “The editor has encountered an unexpected error” After add defer tag to java script
- Show uploaded pdf files dynamically and filter by month name
- Any way to use FETCH_KEY_PAIR with $wpdb?
- I want to add string array to this function to filter displayed option in drpodown [closed]
- How do I check if I can use the allowed_block_types filter?
- Modify WordPress Page Title ()
- Add an attribute to the root from functions.php with add_filter
- Would like to use hook or filters to customize email templates
- Ajax filter – show all results that contain at least one filter
- How to securely controlling data without keeping it in postmeta?
- Removing menus from users other than the administrator
- Filter in Custom post type to find the parent post
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- “BS_” rows in postmeta table
- Delete oldest wordpress post (SQL query)
- how to unescape wordpress output
- Having wp-admin on different domain
- Override wordpress audio playlist
- Use a functions in functions.php to remove a string for template theme
- Drop down filter sort posts by latest, last 7 days and monthly
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- Hook to add content after date in post?
- Function not returning correct value for found_posts filter
- How can I pass instance via apply_filters as a parameter?
- How can I limit access to uploaded media depending on the logged in user’s user role?
- Create different flavours of excerpt
- how to use substr with get_the_content()
- Setting the page title in a plugin, but not outside my plugin
- add_filter doesn’t return false?
- AJAX Post Filter
- How to track a particular page in order to address the loading speed issue
- How to add lazy field in content endpoint using Gutenberg blocks
- Is it possible to assign a css id to a row in plugins list table?
- Mystery line break
- How to bridge the gap between dynamic back-end data and front-end output?
- How to loop year & month condition together to filter correctly via AJAX?
- Can’t understand apply_filter logic
- Consult array data in REST API Filter
- How to add a blog filter bar without paying money. (example inside)
- Database & Post Search
- login_url filter creates permanent wp-admin -> wp-login redirection loop
- WordPress add_filter to post_date