Let’s start from the top:
-
$current = get_the_category();
This returns an array of objects, one object for each category.
-
$current_id= $current[0] ->cat_ID;
This returns an object, the first object in the previous array
-
$categs_list = get_category_parents($current_id);
This returns a string, but only if the current category has parents; otherwise, it returns whatever was passed to it: which was an object
(See where the problem is yet?)
-
$pieces = explode("https://wordpress.stackexchange.com/", $categs_list);
This expects a string, but is returning an error, because it is being provided an object.
So, Conclusion:
You are calling this code in a Post that is in a category that doesn’t have any parents. You need to write some fallback code to account for this occurrence.
Related Posts:
- Code to pull in a PHP file named after the category ID
- in_category() works in single.php but not in page.php?
- Add title, post content, and category like add_post_meta and update_post_meta
- Show only one category
- Implementing a tricky wordpress menu (nested categories + thumbnails)
- Taxonomy filter all children
- Second level subcategory
- query in category.php repeats itself
- Counter in loop in foreach
- Woo Framework: woo_cat_featured not populating
- Create menu locations for each category in wordpress
- Different Output for “Every Other” Foreach Statement?
- Exclude category from foreach loop
- Media Library Category Exclude Tree
- Multiple if statements with else for get_the_category [closed]
- Cant get unique_array() work on get_the_category() foreach loop
- How to add Pagination to foreach loop to page
- How can I modify this code to iterate over an array of categories?
- foreach,having wp_query inside, breaks after showing one result
- Category foreach Paging
- Display only the latest post
- Paginating a list of all posts collected by category titles
- how to edit wp category widget
- Call Current Category
- Page permalink rewrite
- WordPress Multisite – global categories
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Can’t custom taxonomies have same terms (slugs) as categories?
- Using wp_category_checklist in a widget
- How to show subcategories in categories else show posts
- How to remove the parentheses from the category widget
- Filter front page posts by category
- How to get the url to tag & category base set by the user?
- Exclude one category from get_the_term_list
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Root level category, tag, author and archive pages to work
- Number of posts in page – set per category and exclude sidebar
- Display one latest post from multiple categories
- Archive pagination causing 404 with permalinks structure
- Get a list of Terms for a specific category
- Get a variable from object in array [closed]
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- Exclude Child Categories Using wp_list_categories
- a-z list, categories and sub categories in loop
- Category slug $_SERVER[‘REQUEST_URI’];
- wp_dropdown_categories and custom taxonomy + custom post type
- Linking products to categories
- combine Code 1 with Code 2
- How to remove “Category : …”
- Show all posts for a specific category/author
- How to call custom category field data in theme?
- Query Posts Exclude Entire Category
- One Specific Category To Permalink
- Hide woocommerce category name from specific pages
- WordPress category widget only show categories with children
- Woocommerce custom category page with pagination [closed]
- Menus don’t work after 4.4 [closed]
- Custom post and category template pagination problem
- Multiple category selection in post, shows less important category in breadcrumb
- How to list all categories in three divs dynamically based on the quatity of categories?
- Grouping categories by genre
- how to “not” display new posts with a specific category on the main page?
- Limit categories and it’s subcategories for specific group of users
- show all WordPress categories in a page
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Category specific order
- Problems with my conditionals in single.php by category
- Recent post by custom select query
- 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?
- Add custom code at start and end of all posts in a category
- How to hide posts of a specific custom category in WordPress?
- Output category list inside array
- Group search results by category
- Anchor tag generates blank href attribute using echo esc_url( )
- WordPress monthly archive category specific
- admin panel – How to remove “delete” button from category editing page
- Custom Loop with certain number of one category
- “Special” category is displayed in all categories or show parent category on sub category
- How to show WooCommerce Categories on ‘shop’ page instead of products?
- How to list all subcategories from all categories but not from a certain category
- add woocommerce archive description if exist
- Can’t display posts by filtering categories using isotope.js
- Get a list of categories, separated by / to display inside the for custom metatags
- Automatically create tags and merge with categories
- Is there a reason to put a product in both the Child and Parent Categories?
- Get_term_meta() always returns false
- How to list all categories a post is in, but exclude current post´s category on single post page
- Get only children category name
- PHP drop down menu for my get_category child of
- No results found for second level category
- get_the_category vs wp_get_post_categories
- Categories in media library
- WP_query exclude a category unless it has more than one catagory
- Customize category query in widget
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- How to control order when displaying child categories
- Broken category styling
- Trying to WP_Query a category