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;
Related Posts:
- How do I reorder (pop and push) items from WP_Query?
- Reverse chronology of post listing
- WP_Query orderby not working with meta_value_num and menu_order
- How can I sort posts by the date and a custom meta field?
- How to order posts by meta_value and title
- how to get post order by post id wp_query?
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- query posts with selected post ids first
- WP_Query sort by meta_value_num or date
- My custom query is displaying random posts in random order
- Get query result according to merged array
- Order by ‘s’ using WP_Query()
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- Get current post id in functions.php
- WP_Query offset argument does not work
- what types of order can I pass to get_posts() via orderby?
- Querying post from a multisite network
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- Sort post by attributes ‘order’
- Keep getting same permalink with WP_Query?
- How to query posts with current or future date only
- Pagination not working on Custom Page Template
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Post content being duplicated by the_content();
- How to add padding between posts
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Display custom post types by date field
- Add few specific post ids to wp_query
- Custom Order in WP Query
- Search query – exact post title match
- WP_Query posts_per_page ignored
- How to get most recent commented post above new submitted post in WordPress?
- Display posts from #6 to #20 on archive page
- wp_query ‘s’ parameter does not work with custom post type
- How to start with post number x?
- Automatic post deletion
- WP Query – duplicated posts once including tags in search results
- I want to get title name of post, but i didn’t get by this code. Any suggestion?
- How can I show many posts an author has per week?
- recent posts for different categories
- Change post order random through out the entire WordPress
- How to exclude latest x posts from a paginated query?
- Removing noindex posts from wp_query
- Ajaxify This Code
- Pausing and Resuming WP_Query results
- How to : pagination in 3 different custom loops on the same page
- how can i change WP main archives loop to sort by name or title
- While loop articles – if statement order
- How do I extract just the post ID of the first item in whatever WP_Query returns?
- Show post content and title in diferent divs using WP_Query using a loop
- why the same code got different results when using query_posts in functions.php and index.php
- How to get posts published on the latest date?
- Page and post loop same template
- Show metabox value last post excerpt, title and link
- WP_Query: Show 10 posts in date order, first three random
- get_previous_post() while accounting for sticky posts
- Related Posts function not working
- wp_query if have posts show date but not in loop
- Custom WP_Query not working correctly
- Echo the number of posts being displayed
- WP_Query of Category Not Showing First Post
- Creating a related posts section in wordpress inside a default post
- WordPress Query – Display 5 posts (same post type), each from a given tag
- While loop in functions.php outputting the_title() of each post on frontpage
- Show posts from two specific category in WP_Query
- Why sorting posts doesn’t work properly?
- the wp_post_update isn’t working all the time
- Display specific posts based on an ID of another post
- a WordPress connected to 2 database
- Change URL of previous posts and next posts link in WordPress
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- long-title posts do not want published
- Mix post date with post meta value using WP_Query
- WP_Query that targets all categories
- Fill the exclude array() in get_posts()
- The first post appears twice
- Double loop output
- Custom layout manager for posts
- Display WordPress Post By Date
- GUID to related post not in current language
- How to make post button to a random post
- Get results from the main wp_query
- How can I display a specific number of post in a category via a url
- Advanced Post Display/Pagination/Ordering
- Where is object, property or label in the database that controls the order of the posts being displayed?
- Query category-specific, paginated posts and allow viewer to change sort order
- Pagination for custom query won’t let me back on page 1
- Make assigning post to a specific category equivalent to assigning it to all categories
- WP_Query retrieve custom posts but not the post showing
- WP_Query based on a custom field result
- How to get single post by one author?
- List posts related to category on a div [closed]
- WP_query sort by custom meta_key “price”
- Wp_query WooCommerce products
- posts_per_page – Repeats only first posts ‘post__in’ array
- query_posts different amount of posts per page [duplicate]
- date_query returning only the most recent post instead of the post published before today
- How to make WP_Query faster when getting a post from one year ago?