WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently am getting this error:

Warning: explode() expects parameter 2 to be string, object given in D:\...\portfolio.php on line 12

Here is my portofolio.php:

    $current = get_the_category(); 
    $current_id= $current[0] ->cat_ID; 
    $categs_list = get_category_parents($current_id);
    $pieces = explode("/", $categs_list);  //this is line 12.
    $category_name = strtolower($pieces[0]);
    $categs = get_cat_id($category_name);

Any Ideas? PHP is not my forte.

share|improve this question
Could you clarify what it is that this code is even attempting to do? It's completely weird. – Otto Aug 24 '11 at 18:14
up vote 1 down vote accepted

Let's start from the top:

  1. $current = get_the_category();

    This returns an array of objects, one object for each category.

  2. $current_id= $current[0] ->cat_ID;

    This returns an object, the first object in the previous array

  3. $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?)

  4. $pieces = explode("/", $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.

share|improve this answer
Thank you, I'm still getting the hang of it and having someone break the code apart the way you did is infinitely helpful. Thanks! (I'd give an upvote but not enough rep :( !) – Nick Aug 24 '11 at 20:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.