0

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') . "";
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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