Try this code. is it necessary to unset that arrays in foreach? unset inside loop will remove the previous array values.
<?php
//Get posts by the arguments saved in the $args array
$vendor_postlist = get_posts( $args );
$categories = array();
// Loop the list of posts obt.....
foreach ( $vendor_postlist as $post ){
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) {
$categories[] = $term->name;
echo $term->name;
}
}
print_r($categories);
?>
Related Posts:
- Inject post (from specific category) between posts in Loop
- Custom Loop Pagination on WordPress
- delete an array element when its date expires
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- User Defined order on get_categories?
- Custom Loop through category menu to include sub categories
- How to exclude specific category from the get_the_category(); array
- Changing layout with wp_customise
- Filter Select results based on selection
- How to pick the default selected value in wordpress dropdown?
- Alert Bar section within WP loop is displaying even though there are no posts
- Display category name only once inside loop
- how to show only specific category for a template
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- How do I remove a category from a wordpress loop>
- How to get the last category name of a child category?
- How to get current post category details inside “loop”?
- Problem with custom loop and wp_list_pluck [closed]
- Echoing a CSS class based on category of post in a list
- Do not duplicate posts with multiple categories in multiple loops
- How to Fix an Archive.php That Displays All Posts?
- pagination broken – clicking next displays “page not found”
- I need to display posts in subcategory beside posts in main category
- update_user_meta as multiple value but with same meta key
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Return to the beginning of the results of a for loop
- Exclude category and post from loop in custom category.php
- Showing the project type in HREF
- Pagination on Custom Loop
- Error trying import one category on page
- why is this content-template not showing any of my blog-entries?
- Remove the_content From Loop
- Post thats in Two Categories, only want to display name for one
- Woocommerce linking variations
- fetch from an external api call and display results in page
- Show the most popular post per week
- Add a class to links in the visual editor (how to get old dialog back)
- Creating custom Woocommerce attribute taxonomies from a plugin
- Load post content into iframe
- wp_customize_image_control default value
- Want to separate sections of posts. Can you restart loop?
- Two posts in same div – WP loop
- Overriding a theme redux file in child theme
- Widgets not showing in my custom theme
- Edit category output
- Easiest way to show total number of subpages
- How to display custom field on homepage
- Different background-image by category
- How to get 2 or multiple custom post types in wordpress functions.php
- Creating bulk posts with Youtube videos
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- how do I get a specific post from a post with a subcategory in WP
- Get page that displays all children of taxonomy parent
- How to add a do_action on refreshing of WP customizer?
- Counter in loop in foreach
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- post thumbnail, conditions, else wont work
- Define specific category name in PHP
- Category title output before opening title tag
- Why my loop isn’t working? [closed]
- How to get category name or ID by post?
- Get all posts as an array ID => Name
- How to get post ID from button and pass title to Modal
- Listing titles and custom fields of entries within subcategories
- Two Sections on Woocommerce Catergory Page [closed]
- How to wrap every 3 posts in a div (and close the last div too) [closed]
- Dividing the loop to style post differently
- WordPress loop is not working
- Set cookie for visitor
- Display movies that apear this day next
- Adding wp_list_categories to a specific div that was appended using jQuery
- Problem in replacing the_content with the_excerpt()
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Pagination contents not changing in Front page WordPress
- How do I know if the user is a customer?
- How to block specific user id in custom login form?
- I want to fusion the product columns in email table order
- Get parent category name when only child category is applied to a product
- Display all categories including sub categories under a list ul
- Where does php code to load data go?
- Latest posts feed with a specific post always first
- Show subcategory name selected in specific category woocoommerce
- Add custom attribute to product’s HTML to woocommerce cart page
- How fix error in the WordPress loop?
- Efficient way of querying for a “fallback” post?
- Loop 1 user randomly
- Create a hierarchical loop at predefined markup requirements
- Rearrange get_categories array compared to another array
- How can I show only if custom field has content [closed]
- Query seems to be duplicated
- Top menu disapears in Category Pages when filtering using ACF
- Pagenav Not appearing on custom Template
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- Category List in Theme Options Page
- Pagination in category.php not functioning
- How to create a loop that will display one post and stop?