Query ‘orderby’ when there are multiple values for the same meta_key

Sorting by multiple meta keys (ref) may be helpful (untested): add_action( ‘pre_get_posts’, function ( \WP_Query $query ) { $orderby = $query->get( ‘orderby’ ); if ( ‘start_date’ === $orderby || ‘end_date’ === $orderby ) { $meta_query = array( ‘relation’ => ‘OR’, ‘meta_query_1’ => array( ‘key’ => $orderby, // start_date or end_date ), ‘meta_query_2’ => array( ‘key’ … Read more

How to order product for key exists?

The meta_key parameter tells WP_Query to only return posts that have the price_sale_custom meta data. Remove that first, and then change orderby to reference the meta_query values: This is something that WordPress added support for in 4.2: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/ https://stackoverflow.com/questions/17745334/how-to-order-by-multiple-meta-keys

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)