" Invalid argument supplied for foreach()" .
means that the $parents
variable is not an array so you can’t loop through it. You should wrap the foreach
loop in an if
check that verifies that $parents
is something valid.
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$parents = get_the_terms($term->parent, get_query_var('taxonomy') );
if( $parents && ! is_wp_error($parents) ) :
echo "<div class="product-cat">";
echo "In"." "." ";
foreach( $parents as $parent ) {
echo '<a href="'.get_term_link($parent).'">'.$parent->name.'</a>';
}
echo "</div>";
endif;
?>
Though secondarily…. get_query_var('term')
and get_query_var('taxonomy')
are not returning anything on the search page because those query vars don’t pertain to the search query.
Related Posts:
- WooCommerce: List All Categories
- Combine two taxonomies in a hierarchical tree
- Woocommerce product categories order [closed]
- How to split the categories of subcategories with thumbnails
- WooCommerce – Display product child categories from specific parent
- How to order categories in Woocommerce that are spread over multiple pages? [closed]
- How to add categories to products in woocommerce programatically? [closed]
- Display products for a category, sorted by post_excerpt
- Woocommerce – Get product category 2nd level category
- How do you remove display of WooCommerce product category on single product page?
- Show Featured products in product category pages
- Show category images on single product page and product overview page
- woocommerce product category tabs [closed]
- Get Tags specific to Category using WooCommerce plugin
- How to change how many list item show in category generated by file edit-tags.php
- Show button only for certain Woocommerce Product Categories
- Target a specific category from a custom taxonomy?
- How to display product categories and number of sales on WooCommerce
- show category in woocommerce
- Unable to browser posts in categories
- Ajax Response Error
- List products from current category
- Display all subcategories for a product category in woocommerce
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- Add product category to post_class
- Display All Products by Category with WooCommerce
- get_terms vs. get_categories: does it matter?
- What is a good robots.txt?
- Add a URL prefix to permalinks of one category of posts only
- Woocommerce get category image full size
- Add forward slash on categories url (serve one version of a url)
- Elegant way to add parent categories?
- Alphabetical Index Page
- adding custom fields to next and previous post link
- Categories Listing with “selected” category highlighted
- Assign parent category to all posts that are already assigned to child category
- Using same slug name for a page and category
- Related content based on category name
- If no posts in category display Form instead of not found
- Getting WordPress custom taxonomy/category?
- How to run WP_Query to retrieve attachments to posts only from a particular category?
- How to get post category title within the loop?
- If category is in parent category?
- Hide posts of a certain category unless logged in
- WP_Query() returns null when results exist!
- Problem displaying one post from each category
- Limit a meta box to a specific category
- get_posts and multiple categories
- Pagination not visible on woocommerce’s category page
- Only one post is showing on category page, why?
- wp_list_categories set order manually?
- Putting a Category of posts under a Page
- change recent posts based on category
- category pagination got broken suddenly
- Category.php loads first before page.php?
- wp_update_post is not updating category
- how to get full category path including parent and subcategories
- What’s wrong with my wp database query?
- WordPress get from single.php back to the right category page
- Include WooCommerce product to all child categories
- Length of Category Names
- WordPress link to post links to category (loop)
- Display all product tags associated with a specific product category
- How replace individual elements in the RSS feed with a single string
- Category url generate 404 error
- Style a category from category list
- Adding a page summary to a specific page
- Add a category on all archive category pages
- what file I need to create to work date archive links?
- Assigning certain pages or posts to use the template of the parent page or category
- Check for parent category
- I need advice on how to structure the categories according to the layout i have
- How to get posts using category slug in ClassiPress?
- Problem with wp_create_category
- Assign author to category and not only posts
- Sending all categories associated with a post to Google Ad Manager for use with .setTargeting
- Pull in an “Include” file based on a WordPress Category ID
- How to fetch common posts from two feeds?
- Why is URL Slug Saving Differently From How It’s Been Defined?
- How to set acf color field as background color to product category
- How to add all subcategories as submenu in WordPress menu
- How to noindex, follow a specific category wordpress?
- Category pages resolving with and without category prefix
- get taxonomy list in a page in the wordpress
- Is there a way to allow users to customize their feed view?
- Number of categories slowing down the site
- Change post category within pre_get_posts
- Category as Subdomain for One WP Install
- Subcategory Page 404ing
- displaying one category on one page
- Ajax Category add doesn’t update the list table custom column
- Question About Messing With Category Pages and Descriptions
- how to get postmeta info based on multiple categories?
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- List Terms by category
- How to make 10 post of one category
- Is it possible to setup Category wise Subsciption?
- Listing category
- exclude category in loop.php
- How to make /category/ URL load properly instead of 404 error?