wordpress meta query with multiple meta condition causing a load on server and slows down the server..!
wordpress meta query with multiple meta condition causing a load on server and slows down the server..!
wordpress meta query with multiple meta condition causing a load on server and slows down the server..!
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
Short of coming up with a MySQL query yourself, you could get a list of distinct meta_keys and build your query array based on the results. On another note, I think you may have misunderstood the meaning of EXISTS. It doesn’t denote finding the value parameter passed within the value of the given meta. I … Read more
Please use ‘meta_value’ => ‘meta_value_num’ instead of ‘AC’. You can also take help from documentation to see which parameters you can pass for order attribute in the query => https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
You have miss the last parameter from get_post_meta(). Try below code: $literature = get_post_meta(get_the_ID(), ‘popis_literature’, true); It gives you array of IDs. E.g. array (size=2) 0 => string ‘32985’ (length=5) 1 => string ‘59956’ (length=5) So in query you can use them like: $args = array( ‘post_status’ => ‘published’, ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, … Read more
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’);
Multiple values for one variable
What I don’t really understand is how or what the ‘orderby’ => ‘meta_value’, is actually sorting by as the key has multiple values. It doesn’t have multiple values. It has a single value: a:2:{s:3:”day”;s:1:”8″;s:5:”month”;s:5:”March”;}` This is a ‘serialised array’. This is just a way to store an array as a string. As far as WordPress … Read more
meta_query orderby sort multiple keys
You want to use posts_per_page instead of numberposts. Take a look at the Pagination Parameters for WP_Query.