This is a PHP syntax error – you can’t nest a foreach inside an array, you use it to build the array:
$query = [
'post_type' => $post_type,
'posts_per_page' => -1,
'tax_query' => [
'relation' => 'OR',
],
];
foreach ( $taxonomy_arr as $t ) {
$query['tax_query'][] = [
'taxonomy' => $t['taxonomy'],
'terms' => $t['value'],
'field' => 'slug',
];
}
Related Posts:
- How to fix pagination for custom loops?
- Remove the Homepage Query
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Transient not working for custom loops
- post loop causes wp_users and wp_usermeta DB queries for each users
- get_the_foo() in the loop – does it perform another query?
- If No Search Results, Show Posts from Alternate Search Query
- How to Loop within a Loop (Display Children and then Grandchildren)
- Loop posts only excluding first post
- Loop after page content
- A loop with all articles with certain text strings in tags
- Display most viewed post from last 30 days is not working correctly
- Query posts if meta key starts with
- 3 Posts in Loop, Show Stickies First
- How to go about combining dropdowns / filter queries?
- Query reset problem or flawed code to enable custom post type query
- Query last updated posts (posts updated in the last 24 hours)
- Conditional query that displays on Woo product attribute pages
- How do I use AJAX Query in my posts loop?
- woocommerce get_price_html not pulling in correct price
- How to fix pagination for custom loops?
- How can I paginate this?
- How to display posts by vote count and if no value continue with latest posts with no votes?
- How to fix pagination for custom loops?
- Split wordpress loop to multiple layouts
- Making a query to the DB using same parameters of loop
- get_delete_post_link() inside Loop stubbornly returns nothing
- loop inside the foreach
- Query posts only with actual text content (not including shortcode or images)
- Exclude posts based on an array
- Query post & loop problem.
- Loops for cat links not looping for wordpress site
- How do I set the Stewart Search Template to return only published posts in the result
- Trying to get all links in my posts
- Custom Query with Sticky Posts
- Build a Page which shows the Oldest Post with specific Custom Field Value
- Query posts and display all dates in repeater field in chronological order
- How to fix pagination for custom loops?
- Get featured image outside the loop using foreach
- Alternative layout the loop
- Show posts by tags excluding current post
- Strange problem with wp_get_attachment_image_src database (db) query count
- Next 10 posts data of currently viewing post in blog page
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- Get query result before posts are displayed?
- Combine Query and Select Database to create directory loop
- WordPress loop: Display if posts exist
- wordpress showing all posts instead of date range
- Multiple loop with pagination in same page
- Query Loop Block: possible to restrict just child pages?
- Use Base-URL with Query-Loop
- Using Query Loop Block to list all posts under each category
- Split Content and Gallery
- Do I need to use The Loop on pages?
- the_content and wp_link_pages
- as a shortcode within the loop?
- Page template not displaying
- How to get_template_part using AJAX?
- How can I modify the loop from a plugin without wiping out other filters?
- Complex query and posts pagination
- Loop in Related Posts WordPress
- Listing subpages title and content and styling the first iteration differently
- ACF custom field in [closed]
- Update status of all posts in a category
- is_active-sidebar loop
- Unable to change the “Read more” text inside the_excerpt
- Conditional: IF current user has NOT commented on current post (not including post author)
- How to overwrite orderby with add_query_var
- How do I get my loop.php to properly paginate?
- How to display first post
- Pagination on custom post type on front-page.php
- get_template_part() Not Working in Loop
- Limit tags shown in post
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Comments_template doesn’t work
- Get markup for post without loading into the template
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- get post images to link to external sources
- Slug is changing when I use WP_Query in a metabox of a post
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Making a specific page wordpress compatable that is not index
- display only parent replies count in index.php
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- loop mix my child-category and parent-category
- Fix html inside a for loop [closed]
- Insert multiple custom components after x-number of posts
- Query Multiple Post Types and Paginate Newly Created List