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
- Why have on every line
- Admin Bar (Toolbar) not showing on custom PHP file that loads WordPress
- How to add active class to custom menu using while loop and wp_list_pages
- Problems with function on function.php
- Use template for posts with a particular category grandparent
- How do I display the function the_content in this loop?
- How to get to a specific position in wp_query?
- Facebook “like” open graph meta in header.php
- Custom category code not showing all posts
- Taxonomy linked to pages
- Using foreach loop breaks
- How to sort posts based on the value (number) of a post’s metadata?
- Can I install/embed WordPress on a ‘single page’?
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Applying A Category to Existing Posts Where Page Title Matches Regex
- How can I add extra word in permalink when someone click download button?
- Let Users Choose Post Categories
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Custom posts in different columns style
- Can we count the WordPress Loop
- Display most popular posts of category
- get taxonomy thumbnail and use it as a variable in code
- Warning: Illegal string offset on theme options page [closed]
- Is the 404 page automatically displayed if a loop returns nothing?
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- use loop to return blog details
- Check class_exists before class definition / Doxygen problem
- Extract links from content
- How to add post meta in while loop?
- Custom Registration username_exists / email_exists
- Displaying list of posts in category page
- PHP Helper Class to create shortcodes
- Is it possible to add a custom page to a free WordPress site? [closed]
- How to Generate a list of Most Commented post?
- How to pick “full/thumbnail” images in the loop?
- is user member of a group, show them categories [closed]
- How to add ASCII symbol after each recent post [closed]
- List post only under the category, exclude child category content
- Using multiple variables to assign categories to an array
- Search.php gets metadata from first post
- Pagination at category doesnt work with same name of page
- WP-Bakery – Add custom colors to buttons with template colors
- Child-Theme Category View with modified permalinks (%category% removed)
- How to move a post from one category to another
- Create category after theme setup and modify the default one
- Accordion headings cuts off to second line on collapsing a accordion heading (used acf repeater)
- WordPress Recent Posts – Loop
- Search only for posts with specific metadata?
- ACF background-color per post in a WordPress loop
- Displaying 3 Category Posts differently
- Adding custom PHP to existing loop in Genesis
- Is there a way to have chunks of a page’s content expire?
- WordPress using get_term to retreive slug not working as expected
- Static home page ignored
- How do I routinely extract the thumbnail of the most recent post?
- Loop returns more items than exist?
- Front end post submissions do not get submitted in the category
- WP_Post is not from correct array
- Post formating on Home page
- divide custom field values in div every two values
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Showing custom field contents without listing description
- MySQL Engine vs. Charset
- Custom single.php files for different post formats
- Troubleshooting “loopback requests that take too long”
- Remove /category/ from category (archive) page URLs (without using a plugin)