You’re using the order
parameter incorrectly for WP_Query
.
- order (string | array) – Designates the ascending or descending order of the ‘orderby’ parameter. Defaults to ‘DESC’. An array can be used for multiple order/orderby sets.
- ‘ASC’ – ascending order from lowest to highest values (1, 2, 3; a, b, c).
- ‘DESC’ – descending order from highest to lowest values (3, 2, 1; c, b, a).
query_posts
looks to be modifying the main query. In that case, remove 'rand'
from your query args and shuffle the posts directly afterwards.
query_posts('showposts=4&cat=-20,-54&orderby=meta_value_num&meta_key=post_views_count&order=DESC');
global $posts;
shuffle($posts);
if (have_posts()) :
//...
endif;