Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a function that is giving me this error - Catchable fatal error: Object of class stdClass could not be converted to string in.... blah blah

Below is some of the code from the function. It is the last line that is giving the error but I can't work out why. I'm trying to display the term with ID 7 in the project_cats taxonomy.

$html_content .= "<h3>" . rgpost('input_1') . "</h3>"; //Title
$html_content .= "<p><strong>Category:</strong> " . rgpost('input_5') . " | <strong>Budget:</strong> " . rgpost('input_3') . "</p>"; //Category & Budget
$html_content .= "<p>" . rgpost('input_4') . "</p>"; //Description
$html_content .= "" . get_term_by('id', 17, 'project_cats') . "";
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Function get_term_by returns object or array (based on $output arg) on success and false if failed. But you treat it as string and try to concatenate it. So your code should be following:

$cat = get_term_by('id', 17, 'project_cats');

$html_content .= "<h3>" . rgpost('input_1') . "</h3>"; //Title
$html_content .= "<p><strong>Category:</strong> " . rgpost('input_5') . " | <strong>Budget:</strong> " . rgpost('input_3') . "</p>"; //Category & Budget
$html_content .= "<p>" . rgpost('input_4') . "</p>"; //Description
$html_content .= $cat->name;

Read more about this function in codex.

share|improve this answer
    
Awesome, works perfect. Thanks! –  user537137 Jun 4 '12 at 10:53

Your Answer

 
discard

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.