Get post by two meta key but order by one of them

use ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘post_views’, ‘order’ => ‘DESC’, instead of ‘orderby’ => array( ‘post_views’ => ‘DESC’, ), your way is okay for string, but when you use number it is better to use meta_value_num meta_value will sort number weird 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, … Read more

Re-order search results with posts_orderby filter and post meta value

Probably it’s just a JOIN problem: the SELECT query has no postmeta fields to order by. Try to implement the second answer from this question. That is, paste this code in your file. function custom_posts_join($join){ global $wpdb; $join .= ” LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id “; return $join; } add_filter( ‘posts_join’ , ‘custom_posts_join’);

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