try to implode $category with “,” as a glue. Mentioned code in each foreach run rewtites the cat variable of $query.
$query->set('cat', implode(',', $category));
Related Posts:
- Exclude Tags from get_the_tags
- is there a quick way to hide category from everywhere?
- Exclude category from category archive
- pre_get_posts : ‘post__not_in’ doesn’t work with global variable
- how to get posts ids inside pre_get_posts filter?
- Multiple arrays in post__not_in parameter
- Exclude some categories from the post page
- Don’t execute function on specific posts
- problems exluding categories
- Better way to exclude category output for post/pages?
- Disable the link on certain pages
- post__in and tag__not_in conflict
- How to exclude one category
- How to exclude a category in the following Code?
- Exclude Categories from wp_list_categories()
- List post wit the same category but exclude parent
- Display 1 category only with get_the_category (by ID or slug)
- trouble with my loop
- Get first category only and excluding one
- How to exclude first 2 posts from a specific category for a custom post type archive page
- Exclude post ID from wp_query
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- Sorting posts that has a meta value first then the rest of the posts
- Varying the number of posts per page from the first one
- WordPress Number of Posts Not Changing With posts_per_page
- How to alter query order direction using $query->set(‘order’, ‘ASC’); inside a pre_get_posts filter?
- Meta Query “IN” doesn’t work with ACF checkbox filter
- Show only posts which can be commented
- How do I edit pre_get_post for the category the user is currently in?
- Date Query to Pull Current and Future Posts
- Using Sessions to Filter Posts – bad thing?
- Exclude posts with specific meta_value while sorting by a separate meta_value
- pre_get_post filter returns results when there should not be
- pre_get_posts with WooCommerce Shortcode Query
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Why the ‘date_query’ is not working in ‘pre_get_posts’ hook?
- Comparing arrays with meta_query in pre_get_posts
- How to create an archive for all posts that do not have a post format?
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Two loops by pre_get_post on same page
- Including only current user’s posts in search
- How to set post expiration date and time and move the page to archive after expiration [closed]
- pre_get_posts: using tax_query only for certain post type
- How to sort custom post type posts in default order by multiple fields?
- is there a way to retrieve posts that do not have a featured image assigned?
- How to modify archive query with pre_get_posts to append CPTs?
- Show Sticky Post at the top but do not show again in the loop?
- How do I exclude the current post from listing in recent posts
- exclude categories from search results
- hide custom post types with specific meta key ON admin backend
- Avoid repeated post on page 2 when excluding one on page 1
- Woocommerce: Complex query in pre_get_posts [closed]
- Normal PHP array for exclude section of WordPress query?
- pre_get_posts – Trying to get property of non-object warning
- pre_get_posts : only get posts by wp_usermeta value
- Exclude current post from an array of posts?
- Exclude category from query
- Functions.php: Exclude Category from “Blog”
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Compare meta key to current date in pre get post
- Multiple meta_key ordering with pre_get_posts
- Combine “Exclude” Query in functions.php
- How to show the last and newest modified post in a custom category?
- Altering the main query using get_post_meta() in pre_get_posts
- Sort WordPress Archive by multiple oderby arguments in pre_get_posts action
- pre_get_posts works in post type archive but not in single post
- Order posts by taxonomy terms
- unable to customize query to get filtered products by meta_key
- Sort categories by custom field in WordPress admin
- pre_get_posts hook not targeting search results page query
- Order column custom date using pre_get_posts
- Random order not working correctly when using default loop + $query->set
- Setting user permissions per post
- How to hide private posts even if user is admin
- How to show only specific category post by user role without plugin and restrict all other cats
- Exclude Specific Product Category for showing up in its parent category page
- Apply pre_get_posts filter in a certain moment (just for a particular block of posts)
- Modify Taxonomy pages to exclude items in child taxonomies
- Change post category within pre_get_posts
- How order by works?
- CPT year wise archive based on custom date Field
- List child pages, exclude the current page
- WP search in metadata post
- pre_get_posts with multiple post types AND a meta_key
- Extend taxonomy term page with other posts
- How to use get_pages( ) correctly with ‘child_of’ to replace page with child page
- wp_query – Modify $query to include duplicate content
- How to exclude sidebar from pages?
- Fetch post meta in the same query as the main loop
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Problem to show custom post type in archive page category wise
- Adding custom post types to the default loop, yet only posts that has terms from the core taxonomies
- Pre_Get_Posts order DESC not registering
- Avoiding page loop
- Exclude Authors based off date of last post
- WP_query sort by custom meta_key “price”
- How to pass >= condition filter to my year custom tax_query
- Show all tags but exclude a certain tag
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)