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
- How do I get the attributes of a short code from a post?
- WordPress Number of Posts Not Changing With posts_per_page
- WordPress category & taxonomy loop with pagination
- Changing behavior of the loop twice in one page
- post__in – Placing content from a foreach loop inside of an array
- loop query exclude meta_key with meta_value
- “Blog pages show at most” in The Loop
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- Post Loop not Returning Permalink
- Displaying child page content of a certain parent
- Content/Excerpt length control for a specific loop?
- Why we use if with while loop?
- Loop repeating design pattern
- How to get to a specific position in wp_query?
- Sort Posts By Category?
- Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?
- Loop within a loop (Again) for template
- How to use current_post to open a new unordered list every five posts
- Rating system and changing the loop
- Ajax Button to load more Posts into a timeline
- How to target thumbnails of the first post in the loop
- Problem getting current post tags to show in a widget
- Include multiple page ids in loop
- Output meta into arrays
- Moving wordpress to different url/server creates redirect loop
- Pulling in featured image into default recent posts widget
- Modify loop output for a specific list of categories
- Print the whole page?
- Pagination for two loops
- Loop info in jquery Tabs – loop into a variable?
- Adding $args to wp_schedule_event() causes hook to add infinitely to WP Cron
- $post is undefined in wordpress loop [ajax]
- Insert content above an embedded video inside Wordress’ php the_content
- Check value of post meta within IF statement
- My WordPress installation doesn’t load correct template
- Work arounds for conditional checks inside the loop in search.php?
- Get Sticky User in user loop based on user role
- Popular posts with Varnish ESI
- Querying posts from only one category and exluding the latest post
- query_posts ignores the argument
- Need some help with “the_widget()” function
- Exclude Authors based off date of last post
- Loop from another WP site onto mine
- Having issue with WordPress loop
- How to add class to the last image of the last post in a loop
- Hide old posts each year