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
- Add More Featured Data Not Sending to Database
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- PHP can I add line numbers to file_get_contents()
- How to get 2 or multiple custom post types in wordpress functions.php
- Weird problem happening with custom taxonmy when creating/updating posts
- multiple if statements [closed]
- Multiple choice in a custom taxonomy
- How to select WooCommerce products by post_meta and order them
- How can I add pagination and how can I change thumbnail size?
- Custom category code not showing all posts
- Displaying theme options in css
- Creating bulk posts with Youtube videos
- How to Display a Single Post Excerpt
- have_posts() execution failure
- Category Thumbnail Display – How to display ONLY the main Category
- Where do posts get the sidebar from?
- Random Default Avatar Function
- How does the ternary operator work in the wordpress loop post?
- $wpdb->flush(); breaks the loop
- Use object in template part
- Hide wordpress field if data is empty in post!
- Change the site tagline (or similar) based on current page
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- get current product name in functions.php
- Get first URL from post content
- Setting custom canonical urls
- Only show search results with if current date is between two dates?
- database interactions using OOP
- Customizer: Output default value in Customizer CSS
- How can I add multiple ‘tax_query’ arrays via a loop?
- ACF page while loop breaks footer while loop
- How to add just one specific page to widget without plugin?
- Remove one value in dismissed_wp_pointers?
- get post based on category chosen in drop down – The ajax method
- How to use transient in this code for related post?
- create a select input with menus created on a custom options page
- Taxonomy linked to pages
- Creating a related post section based on similar categories
- Swapping wp_dropdown_categories function with wp_category_checklist
- Using foreach loop breaks
- Cannot display or echo alt text on featured image
- Using Advanced Custom Fields to create a per page slider
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Split loop into two columns, how to favor one side over the other
- WordPress Search Results for Multiple Post Types
- Accessing data from a non-WP database/table within a page content
- WordPress blog post url on category page
- WP dynamic featured image – Can’t get second featured image url
- Converting HTML Template to WordPress Theme
- Extending the WP_Widget_Text class
- Proper syntax or method for keeping url in modified isotope / category links
- Display post category in foreach loop with category link
- Dynamic Stylesheet loads but doesn’t finish
- Second level subcategory
- Using loop pagination on single.php
- Loop with slider (slider not loading)
- Selectbox in admin panel function linking to CSS
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- Can I install/embed WordPress on a ‘single page’?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- What is an equivalent of single_cat_title for getting the slug of the category?
- Issue adding sub category programmatically