There’s one way with:
$args = [
'post_type' => 'post',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => 'true',
'_shuffle_and_pick' => 3 // <-- our custom argument
];
$query = new \WP_Query( $args );
where the custom _shuffle_and_pick
attribute is supported by this demo plugin:
<?php
/**
* Plugin Name: Support for the _shuffle_and_pick WP_Query argument.
*/
add_filter( 'the_posts', function( $posts, \WP_Query $query )
{
if( $pick = $query->get( '_shuffle_and_pick' ) )
{
shuffle( $posts );
$posts = array_slice( $posts, 0, (int) $pick );
}
return $posts;
}, 10, 2 );
Related Posts:
- Is it necessary to use wp_reset_query() in a WP_Query call?
- Post_count only shows the number of results per page
- how to show posts that are missing a meta_value
- What is “main query”? [duplicate]
- Secondary Sort (fallback) for WP_Query
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- How to paginate attachments in a secondary query as gallery?
- How to stop wordpress to make the default query?
- How to make an activities stream mixing posts and comments?
- WP_Query based on URL parameters
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Order posts ascending with number in title
- How can I style future post?
- List taxonomy terms plus their latest post ordered by post date
- using wp_query to return posts w/ comment count > 0
- Order by meta_key in custom post type doesn’t affect the query
- Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?
- Add a default meta_value to new posts
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Too many posts cause slow load when paginating
- Order Posts by meta value AND published date
- Pass array of taxonomy terms to wp_query
- Formulate a url to show posts with both taxonomy terms
- List of the years with posts presented
- Query custom post type by custom taxonomy (category slug)
- Advanced Taxonomy Queries WordPress
- Getting post revision and printing them on the post content site
- Editing the default wordpress search
- Slow page loads due to WordPress Core Query
- wp_query for multiple cities (multiple values in a metabox)
- Adding column to wp_posts table or join wp_posts table with another table
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- Pre-Populate $wp_query settings with custom rewrite rules and custom template_redirect
- exclude a post from wp_query loop
- Is_single() conditional tag returns null in query
- Is it possible to query a custom field where the value is between two fields?
- WP_Query args to show posts from specific custom taxonomy
- How to query woocommerce product by pricing? [closed]
- filter wp_query result with custom field values
- Posts in loop all show the same author when there are many authors
- Show a 404 error page if Public query variable’s value doesn’t exist?
- WP_Query within function within WP_Query
- If have posts a week old, display, else display a different loop
- All blog data on a page using custom query gives 404 for page 2 and onward
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- Where is the extra SQL fields coming from?
- construct complex queries with WP User Query
- How do I fit WP_Query arguments into a function?
- Create one-use post dynamically, add to main query, do not insert post (user profile view)
- Why always one post missing
- Is there ANYTHING about this query that’s incompatible with WordPress 2.9.2?
- get all images from the wordpress media library with link to the post they are associated with
- adding pagination to a foreach loop in wordpress
- Add metabox if there is at least one post available
- Custom Taxonomy – Modify Function to Get Child Category
- WP Query – grouping posts by same meta key, adding together values from another key
- setting offset to category number in archive page
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- Pass post ID to JavaScript outside the loop
- Query for current post
- Access queried post ID in WP_Query
- Loop through array of pages
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- Filtering posts for unique titles, only the most recent
- How to show post title in content editor in backend?
- How do I hide submenus from the top menu bar?
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- What is the best way to reset a search on a meta_key / meta_value?
- View related categories in order of posts
- query only returning posts with already set custom field
- Using URL variables on a custom WP_Query
- Sorting posts by meta values: 2 different orders
- Escaping WP_Query tax_query when term has special character(s)
- How to get hierarchical number of custom taxanomy
- Show parent’s child and also child’s, child on a page?
- Show posts in category
- Is there any difference between below WP_Query code snippets?
- Order by three custom fields (Y-m-d), then separate into yearly sections
- Both WP_Query and get_posts returning 1 post
- Using WP_Query to re-query and sort results using a date?
- Geo location query inside wp_query?
- wordpress query from multiple post id
- Get the tax term in which is a post via wp_query
- Using WP_Query to get attachment returns empty set
- wp_query display posts based on day
- meta_query compare not doing what I want it to do
- Displaying specific posts from query thumbnail outside div
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- Get author meta data with no published posts in author.php?
- how to fetch post_name from WP_Query using Group by a custom value field
- How to display only top posts of parent categories in loop via WP_Query?
- Empty query on Custom Post Type, using WP_Query or get_posts
- Give attachments an archive page, and exclude unattached ones
- The permalink redirecting to current article on single.php page
- Variations as Single Products [closed]
- Bulk delete comments, foreach loop