I've a really strange issue with Wordpress and the get_the_link()-function and a following issue with objects who are objects, but identified as non-object-error, itself they are working.
First the get_term_link() Issue:
If I ask with a normal number and taxonomy, it works well:
$tax_name = 'products';
print get_term_link(13, $tax_name);
It returns the url, but if I do it like following:
$tax_id = (int)$navItem['id'];
$tax_name = 'products';
print get_term_link($tax_id , $tax_name);
I got the error-message:
Catchable fatal error: Object of class WP_Error could not be converted to string in /home/username/www/domainname/wp-content/themes/theme/sidebar-left.php on line 89
Which last line was 89. ( var_dump of tax_id was int(13) )
Without the (int) before the navItem['id] var_dump resulted in string(2).
Tried this with a get_term_by()-function as source, too.
$term = get_term_by('id', $navItem['id'], $tax_name);
$tax_id = $term->term_id;
var_dump($tax_id);
$tax_name = 'products';
print get_term_link($tax_id , $tax_name);
Got a new error message as additional :
Notice: Trying to get property of non-object in /home/username/www/domainname/wp-content/themes/theme/sidebar-left.php on line 88
What's wrong, because line 88 is in this example "$tax_id = $term->term_id;"! I can use (int) but this don't change the error-message.
The funny thing is, the $term variable is an object. And this error message explains me that I try to get a property from a non-object. If I convert this object to an array (get_object_vars()-function), and access the values in the array like an array (name[key])
I get the following error message:
get_object_vars() expects parameter 1 to be object, null given line 86
I tried to convert them to integer, then to string. Tried to use slug instead of ID. But nothing worked. The results working!
Yeah! All showed lines returning the correct link-url!
But I get this error messages... and I don't understand why. Because... they are totally illogical for me. But I think or more, I hope that I'm the illogical part of this issue and someone can help me to solve/understand this.
And NO... I don't like to turn/hide the error-messages.