Unlike a normal WP_Query()
, get_terms()
or WP_Term_Query()
does not have random ordering. You would either need to do it in SQL yourself or grab all the terms and shuffle them, pulling out 6 to make your random term array:
// Get all terms
$terms = get_terms( array(
'taxonomy' => 'webshops',
'hide_empty' => false,
) );
// Randomize Term Array
shuffle( $terms );
// Grab Indices 0 - 5, 6 in total
$random_terms = array_slice( $terms, 0, 6 );
Related Posts:
- Show posts without term
- Why is my WP_Query not working when tax_query terms are an array?
- Get list of posts which have at least one term from a custom taxonomy with WP_Query
- List taxonomy terms plus their latest post ordered by post date
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- Order terms inside a select dropdown
- Get array of current post term ID’s
- How to add terms to my tax_query based off of the current post
- Change default ordering of taxonomy terms – pre_get_terms
- Empty tax_query array returns an empty array
- Pass array of taxonomy terms to wp_query
- Get list of terms that have posts in another term
- Formulate a url to show posts with both taxonomy terms
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- Order by slug in get_terms with multiple taxonomies
- WordPress Related Post by tags in Single.php
- Function get_queried_object() return NULL in custom taxonomy
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- List custom taxonomy terms sharing posts with a term from a second custom taxonomy
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Get authors by term id or slug
- How to order posts by title after they have already been sorted by category
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- Taxonomy order exception for specific term
- Filter Custom Taxonomy Posts
- Get posts from multiple tax terms
- How to Order a list of taxonomies? orderby?
- get_the_terms – but only show 4 Posts
- Count posts per taxonomy else change taxonomy if less than x number
- How to add custom meta to ‘pre_get_terms’?
- get term id from term name
- WP_Query to output chosen term and posts with no term assigned
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- How to print term name inside wp post loop
- Using WP_Query for categories instead of get_terms
- Check if a post has term inside loop
- Grabbing taxonomy terms and inserting them into an array
- Deleting terms from the WordPress wp terms table
- Can’t get term id for category archive
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- How to make a post with certain taxonomy term display first before other post with only one query?
- How can I order a post query’s results based on the number of matching taxonomy terms?
- Only show tag with the same id as the post
- display ACF repater field in archive page
- Save queried result into database
- WP Query by 4 different taxonomies
- Get categories within specific term
- How to display Woocommerce products list by tag
- taxquery taxonomy get terms
- get term objects and post objects in query
- How to show terms from another taxonomy
- How to define a custom hierarchy for terms?
- Add a custom variable to query page object
- How to get several fields from wp_query?
- query only direct child and sub-terms of a current term archive
- Get access to all terms associated to each post that the wp_query loop displays
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- I need to get all categories from a WP_Query
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- How to display page content in a page template?
- Display List Of Posts Containing a Relationship Field Value [ACF]
- How to get random posts and order them by date
- WP API to fetch all the media/posts records if count is more than 100
- Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy
- WP Meta Query for some meta (array) values
- posts2posts query using connected_items array issue [closed]
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- How to display posts month by month?
- Extending woocommerce admin product search
- Pagination is broken and I need help fixing it
- Check on which page specific result exist
- Fetch posts that match term slug first two letters (wp query)
- Query Page Content From Theme Options?
- next_post_link / previous_post_link not working with WP_Query
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Get all posts with empty meta_value
- Count identical post titles
- get_page meta query not working, maybe a bug?
- Query by date from custom field
- What is wrong with my WP_Query Arguments?
- specific post is not excluded from the loop
- Sort posts using multiple custom fields and menu_order in single query?
- get_the_terms has strange result since version 6.0
- How to allow a variable with “/” in wordpress url
- How to get taxonomy image attached to a Post Type WordPress
- How to display a post(by id) along with css in a page?
- update_post_meta performance in a loop woocommerce
- Display posts side by side with custom query
- Is there a way to control both Order By and Order query parameters from one input field
- Custom Order Current Query: By Meta Key and Category
- How to modify WP Query to target the first most recent post to adjust content
- Some doubts about how the main query and the custom query works in this custom theme?
- get_posts works but new wp_query doesn’t
- $query conflicting with other queries in the same page
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- How to sort by post_date and meta_value_num?
- Limit paginated result set to a maximum number of posts
- Custom query with custom filtering returning incorrect results
- Best performance for use Custom Field in WP