Hi this is the code I am using on website, but it's giving me
Catchable fatal error: Object of class WP_Error could not be converted to string in /home/capritra/public_html/wp-content/themes/betheme/index.php on line 181
I have copied code from internet, it's working for people but not for me. Can someone help out?
<?php
$term_id = get_queried_object()->term_id;
$taxonomy_name = get_query_var( 'cat' );
$termchildren = get_term_children( $term_id, $taxonomy_name );
// Loop through each child taxonomy term
foreach ( $termchildren as $child ) {
// Get the term object
$term = get_term_by( 'id', $child, $taxonomy_name );
// Get the values we need to output
$url = get_term_link( $child, $taxonomy_name );
$name = $term->name;
// We make the call here to get the image and we pass in the term we want the image for
$image = get_field('kategorija_slika', $term );
// Output it all
echo '<div class="col-sm-4 sub-caregory">';
echo '<a href="' . $url . '">' . $name . '</a><div class="sub-caregory-image"><img src="' . esc_url($image['url']) . '" alt="' . esc_attr($image['alt']) . '" /></div>';
echo '</div>';
}
?>
get_queried_object()
might return aWP_Error
instance. You have to test that (is_wp_error( $term )
) before you use the properties. – fuxia♦ Dec 10 '16 at 14:01