You have syntax error in tax_query
.
'tax_query' => array(
array (
'taxonomy' => $term->taxonomy,
'field' => 'term_id', // this is default value, so can be ommited
'terms' => $term->term_id,
)
)
As you can read in Codex, possible values for field
parameter are: term_id
(default), name
, slug
or term_taxonomy_id
.
In this question you can read about another method of getting a random post.
Related Posts:
- Why is my WP_Query not working when tax_query terms are an array?
- How to add terms to my tax_query based off of the current post
- Is it possible to dynamically get queried term AND taxonomy?
- WP_Query tax query part of slug
- Taxonomy Query Relation field not behaving correctly?
- Loop posts based on permalink term
- Show multiple tax_query from 2 or more post_type in a single code
- WP Query should show No Posts when tax_query $args taxonomies don’t have associated posts
- wp_query with meta_query and tax_query
- How can I get all the posts that are related with a specific taxonomy term?
- Custom taxonomy and query multi conditions
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Get the tax term in which is a post via wp_query
- Custom query for certain post type OR another post type with a certain category
- WordPress tax_query “and” operator not functioning as desired
- Search custom taxonomy term by name
- Escaping WP_Query tax_query when term has special character(s)
- How to display post from current Taxonomy in archive page?
- How to stop wordpress to make the default query?
- $wp_query initiation?
- Display posts the match taxonomy term linked from wp_list_categoies?
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to combine tax_query and date_query in WordPress
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Using tax_query reverses my post_type argument in a custom WP_Query
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- tax_query shows no results if nothing is selected
- get complex results set according to category structure
- WP_Query tax_query problem
- Filtering posts by custom field value not working
- Order taxonomy terms in alphabetical order
- Empty tax_query array returns an empty array
- How do I search inside specific taxonomies in WordPress
- Pass array of taxonomy terms to wp_query
- Formulate a url to show posts with both taxonomy terms
- tax_query: Order by slug?
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- Output an array of terms for a ‘tax_query’ => array()
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Advanced Taxonomy Queries WordPress
- WP Query Args – Title or Taxonomy Value
- Slow queries on a huge database
- wp_query args adding muitiple tax_querys
- Automatically Query Parent Taxonomy
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- Is there a better way to pull in custom content without querying posts?
- Query with meta_query and tax_query together not working properly
- Custom taxonomy.php not working
- Adding a tax_query to a WP_Query Object
- WP_Query for a taxonomy with different taxonomy types
- Finding WordPress Posts assigned to multiple categories
- Order or Orderby in tax_query (How to define order of terms in WP_Query)
- Using custom taxonomies in a query
- How to Order a list of taxonomies? orderby?
- How to add custom meta to ‘pre_get_terms’?
- Get Child Category only
- How to add tax_query to $args with concatenation
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Function using get_posts() with tax_query not working when called from functions.php
- Tax_Query using WP_Query not working
- Custom taxonomy in WP_Query not working
- How to stack name list in non-alphabetical order?
- Can’t get term id for category archive
- How to make a post with certain taxonomy term display first before other post with only one query?
- Any quicker alternative for WP_Query “NOT IN”
- Tax Query on product_cat using NOT IN as operator does not exclude that category
- Use get_cat_ID to retreive multiple category IDs
- 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
- How to use the Term Object from a custom select field in a query
- WP_Query for a taxonomy value OR a custom post type meta field
- WP_Query paginate with one term per page?
- Select multiple categories with is_tax
- list all post who have mutual taxonomy as current taxonomy!
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- pages shortcode filtering by category
- WordPress tax_query ignoring relation OR
- How to show terms from another taxonomy
- Taxonomy Terms That Don’t Exist Display Results
- display all posts from category with and without terms in chronological order
- Search Filter With Custom Taxonomy and Custom Fields : How do I handle it via plugin?
- In Product Category archives how to show Posts having same/similar prod_cat slug structure?
- Category Archive not working for pages
- How to combine nested tax_query logic with other nested query logic?
- WP Query with sticky posts and tax_query
- tax_query not working for taxonomy slug
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- Custom query for tag and custom tag from 2 post type
- Search format not matching taxonomy query
- List posts of terms but exclude one term
- Passing query variables to a custom page template
- How to use tax_query other than by slug or id or solve custom taxonomy tags conflicts with pre-existing tags?
- Advanced AND tax_query in sidebar with 2 taxonomies
- Output ACF field dynamicaly within a taxonomy loop [closed]
- tax_query not working properly with get_posts
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2