$randomPosts = get_posts(array(
'orderby' => 'rand',
'posts_per_page' => 5,
'tag' => $tag,
));
Take a gander at the WP_Query
documentation. get_posts
uses WP_Query
under the hood, so you can use any arguments that may be used there.
Related Posts:
- Display sorting options dropdown when using WooCommerce product category shortcode
- Drop down+sort blog posts date added/most popular
- What is the most efficient way to search users by their display name?
- Archive listing of posts by publish year (multiple years)
- Sortable admin column for one meta key with three possible meta values
- list posts and wrap them alphabetically A-Z
- Nesting if statements to echo only one string based on what tag was filtered?
- Sort posts by custom fields value using dropdown menu
- How to Sort posts by Vote Count?
- Sort query_posts for Parent Pages to menue order or the count?
- How to sort posts based on the value (number) of a post’s metadata?
- Sort custom meta column by other meta value
- Sort the result of the main Query in shop page by a custom taxonomy
- Sort by page information by Ascending Numbers
- How to keep track of when a vote is cast?
- change the default order of posts only for specific categories
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- How to tag the main tag? [closed]
- Removing custom sort order from admin page listing
- WordPress sorting posts by date and title using a dropdown
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- Array sorting assistance
- Page 2+ of taxonomy archives does not recognise sort-order from dropdown
- Query category-specific, paginated posts and allow viewer to change sort order
- Sort posts by title, sort array by largest number [duplicate]
- WordPress – show all posts + ones with specific tag
- ISOTOPE – Missing/Invalid Arguement Get Terms
- Posts sortable column not sorting properly for custom field numbers
- category & sub category order issues in wordpress
- Sort author list alphabetically
- What is wrong with my sorting logic?
- Getting the action’s tag name within the action
- WordPress Infinite Scroll without using any plugin
- Admin Bar (Toolbar) not showing on custom PHP file that loads WordPress
- How to add query vars with paginated URLs?
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- How to Join two tables from separate databases within WordPress
- How to find objects by terms
- Get only the grandchildren, not the direct children of page/current page?
- How to add SVG icon above product tab title
- WP_Query sort using multiple numeric meta values
- How to get to a specific position in wp_query?
- custom widget on the footer
- How to use transient in this code for related post?
- Why is $_REQUEST an empty array in admin-ajax.php?
- Change behavior of the tag
- Is it acceptable to treat a filter like an action?
- Fetch post block/field data as JSON with WordPress API
- How to pre populate a form field with a link of a current user’s author profile?
- wp_head function not outputting
- PHP echo inside javascript
- Value prints outside of the echo
- If ‘editor’ is empty, then
- Different Subdomain changes page content
- Removing the comment function within wordpress
- Display Yoast meta-description `wpseo_desc` within loop of categories and fail silently if no data is set [closed]
- Does get_post function counts as view?
- Get ACF options field in PHP acting as CSS
- Permalinks are not working in WordPress in digitalocean
- Bootstrap Carousel HTML structure and funny output [closed]
- Amend theme php to include certain category in header
- add category to posts with tag wordpress
- Missing a text-domain esc_attr_e
- Get all posts from categories
- How to add post classes?
- How to Generate a list of Most Commented post?
- Updating From Mobile App – Exposing Site to Hacking
- is user member of a group, show them categories [closed]
- How to add ASCII symbol after each recent post [closed]
- Export post data with xml to other site using php soap
- Execute PHP code only with specific user role
- Repeat a function with 24hrs gap for n number of days
- Add a custom WooCommerce settings tab with sections
- How to serve WordPress folder over subdomain?
- How to call my PHP function with AJAX ? wp_query
- Get the same SKU from woocommerce itself for simple and variable products
- Show sidebar only to author of post
- No more get_option(‘date_time’) in WordPress 5.5?
- how to add custom select field to wordpress edit page
- How to update post content of all posts with tag?
- Make WooCommerce product categories only show images on homepage
- How to Change Site Elements based on referring URL
- WP post meta – for loop inside for loop
- WordPress Query Crashes Browser
- WordPress using get_term to retreive slug not working as expected
- auto metakey value on post tile
- Static home page ignored
- Front end post submissions do not get submitted in the category
- How to pass parameter that ends up being part of a class name with wordpress shortcode
- how to check for wordpress Query errors
- calling a function from a class in your template
- Custom single.php files for different post formats
- Troubleshooting “loopback requests that take too long”
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- Order woo products, but first products must be with acf fields
- Remove /category/ from category (archive) page URLs (without using a plugin)
- JSON Object Value Show Undefine
- Custom WP LIST Table filter
- Redirect posts to post editor page based on query string
- How do I stylize selected comments?