It’s because you’ve created an array with explode and assigned it to $string
, then you’re appending strings onto it when you use the .=
concatenation operator within your foreach
loop.
here’s a simpler method:
$string = '-' . implode( ',-', explode( ' ', $data['exclude_categories'] ) );
Related Posts:
- exclude category from get_posts?
- Exclude the category from the WordPress loop
- Exclude certain category from latest updates
- Exclude categories from Loop, queries, widgets, post navigation
- List posts by category exclude current post
- wp_list_categories exclude not working
- Excluding a category from next and previous post links
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- How to exclude categories from recent posts, recent comments & category widgets?
- Exclude a category from the filed under list only on some templates
- How to exclude posts from a category when using this particular format
- Exclude category from Tag Template
- exclude post from displaying in loop if it is in a category, but not in many categories
- I need to create a search form that will display search results from specific category
- Exclude Posts From Specific Category from Next and Previous post links
- Query Posts Exclude Entire Category
- exclude categories from search results
- Exclude category from fucntion
- WordPress category widget only show categories with children
- wp_list_pages() exclude category
- Exclude category from query
- Functions.php: Exclude Category from “Blog”
- Woocommerce filter function not updating
- wp_list_categories not excluing multiple ids
- How to exclude posts from category posts count
- Exclude category from foreach loop
- Have posts that belong to multiple categories, exclude some categories from homepage
- Exclude all subcategories in the_category (post)
- I need to exclude from a query a category and a few custom taxonomies
- Exclude categories by ID
- Homepage custom recent news
- Exclude the category in WordPress
- How can I exclude a category from the main loop with the category name & not ID?
- User level categories
- Exclude category from drop down list form
- exclude certain categories form archive widget
- How to remove an item from a custom Walker_Nav_Menu
- Exclude a category and post_type from wp_query
- How can I exclude a particular category from my WordPress Page 1 and Page 2?
- Exclude category from WP_Query args not working
- Displaying Category in sidebar post widget but not in the loop on home
- Category menu that filters out empty categories
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- How to have a category not show up in query post with page panigation?
- Customize category query in widget
- Call function on a single page
- Excluding cateory not working on my site. how to solve this? [closed]
- How to define category ID in an array?
- Activate Gutenberg in category-descriptions
- How to show subcategories in categories else show posts
- How to remove the parentheses from the category widget
- How to: 301 Redirect /category/ to /customname/
- Display one latest post from multiple categories
- Archive pagination causing 404 with permalinks structure
- Get a list of Terms for a specific category
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- How Do I Merge Categories With phpMyAdmin
- Edit the markup of categories list
- Show category children, one level
- a-z list, categories and sub categories in loop
- Category slug $_SERVER[‘REQUEST_URI’];
- wp_dropdown_categories and custom taxonomy + custom post type
- Show all posts for a specific category/author
- Resort get_categories
- How to call custom category field data in theme?
- One Specific Category To Permalink
- Woocommerce custom category page with pagination [closed]
- Custom post and category template pagination problem
- How to list all categories in three divs dynamically based on the quatity of categories?
- Grouping categories by genre
- Limit categories and it’s subcategories for specific group of users
- show all WordPress categories in a page
- Category specific order
- Problems with my conditionals in single.php by category
- WP_safe_redirect not working
- Do not show sub categories in the loop on archive-product.php
- Having a template per category? Bad for server overhead?
- Anchor tag generates blank href attribute using echo esc_url( )
- Get categories related to particular category
- Exclude the category of the current post
- Output Title of Post’s Current Category
- Excluding current category from sidebar’s post widget, elementor, query-id
- Show subChild categories
- Return all Tags and Categories in Separate List
- Featured Category or Special Category in WordPress
- Change background image page header overlay for each category
- List non-empty categories from a custom post type
- Creating a linkable category list with post count
- Querying posts from two different categories while looping inside another loop
- Loop doesn’t work
- Getting Post Tags From Certain Categories
- Getting page/category content to show up in my custom page template
- Show only one of the categories of a post in the breadcrumb?
- Wrong category being displayed in URL
- Check if a post is in specific category to show an icon
- How to populate a WordPress install with a lot of categories, quickly?
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- How to control order when displaying child categories
- Custom EndPoint not working when strip child category in URL
- How to add custom prefix before category base for category page URL?