The filter on posts_orderby
should return a string that does not begin with ORDER BY
, WordPress will add that itself.
By default WordPress will filter by post_date
. If you don’t want that, you should overwrite the order clause, not append to it. So your filter should look like this:
function filter_orderby( $orderby ) {
global $wpdb;
return " STR_TO_DATE({$wpdb->postmeta}.meta_value, '%d/%m/%Y') ASC ";
}
Related Posts:
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Filter WP_Query for posts having a certain meta-value
- Compare WP Custom Field date
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- WP_Query – Order results by meta value
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- Filter by one custom field, order by another?
- Is there any action filter/hook for validating a custom field before publishing the post?
- Can I query custom meta data through WP_Query
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Apply the_content filter to a custom field with multiple values
- Meta Query with AND & OR?
- So much data in postmeta
- Pass all custom fields through the same filter on post load?
- Sorting a query by custom field date
- What is the advantage of the wp_options design pattern?
- Convert jQuery Datepicker Format to SQL Date Format
- How do I search an array stored in a custom-field using WP_Query?
- Date, Time, and Timezones
- Filter results with custom field values and dropdown
- How do I order by multiple custom fields using wp_query?
- Archive sorting functions by custom fields (front-end)
- Trying to perform complex custom field query with order by set to field value
- Query meta field using between
- Order Posts by Closest Numeric Values
- 2 orderby in wp_query with 2 custom fields
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- How to get a meta value from all post
- Change content before writing to database
- WordPress Search Custom Meta Field Only
- Compare meta_query decimals not working right
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- WP_Query multiple use of relation and/or
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Using custom fields in a filter hook
- Want to filter only parent post in admin area
- Add an advert every nth Paragraph
- Using OR in WP_Query negates the “NOT EXISTS” compare
- WP_query : meta_key with custom rule for specific value
- How can I combine meta_query queries?
- custom field value date convert to unix timestamp problems
- Custom Field sort not working (WP 3.8.1)
- Using WP Query to search by multiple meta fields
- Get multiple custom field values in a $wpdb query [duplicate]
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Order by value in serialized custom field
- $wp_query meta_key naming issue [closed]
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- Meta_query and numeric comparison [closed]
- converting custom field date format
- Force hide custom field metaboxes
- Saving custom profile fields
- Adding Custom Fields to Search
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Any way to include custom fields in WP_Query results?
- Update posts after populating ACF field value [closed]
- Order by custom table and multiplication
- How to validate custom field on lost password form before the user id field?
- Multiple relationships in a query
- WP Query Returning All Posts
- How do I use wp_query for WordPress search?
- Meta query with timestamp using WP_query
- Conditional custom field query
- Order query by meta_value with multiple custom fields
- Auto Populate Custom Field with Complex Value That Increase by One?
- filtering custom post types via meta data drop down
- global function to apply filter to custom field
- Show 1 post and after a specific date show the next one
- How to order posts by one custom field and filter them by another one?
- Filter multiple custom fields Values with Check boxes
- How to get categories with posts by custom field value?
- Custom WP_Query for WordPress Search Results with meta_query
- Meta Query And/Or
- How to combine custom fields to make one order-able value
- Redirect to another page using contact form 7? [closed]
- How to Wrote Simple Calculations by Using Custom Fields in Loop?
- Custom Query based on custom field of a single post
- Passing meta_box string to post__in?
- Best filter to use for modifying custom fields on a post?
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- meta_value and meta_key filtering returning no posts [closed]
- How to display childrens custom fields?
- Select custom posts by meta_value and sort by a different meta value
- Build index page from custom fields
- Can’t query by meta_key
- Adding custom field and querying from post table
- wp custom field date format compare
- Access ACF fields within custom preview function?
- Sort posts by clicks on download button
- Query posts using less than
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- Get emails from users by custom field SQL
- Let Users Filter Posts by Custom Fields
- Meta query relation ‘OR’ not working as expected
- Help setting up a sql query
- How do I convert all custom_field php timestamps in the database to js timestamps?
- The best way to collision check in WP