I'm using Anywhere Elementor to design a taxonomy archive template. I use this shortcode to show all the term
// Add Shortcode
function categorias_shortcode() {
$taxonomyName = "families";
$parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false, 'suppress_filters' => false));
echo '<ul style="list-style: none; margin: 0; color: white !important;">';
foreach ($parent_terms as $pterm) {
$terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false));
echo '<li><a style="color: white !important;" href="' . get_term_link( $pterm->name, $taxonomyName ) . '">' . $pterm->name . '</a></li>';
foreach ($terms as $term) {
echo '<li style="margin-left: 20px;"><a style="color: white !important;" href="' . get_term_link( $term->term_id, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
}
echo '</ul>';
}
add_shortcode( 'categorias', 'categorias_shortcode' );
And it worked perfectly until I tried to translate this page. WordPress give me this error:
Recoverable fatal error: Object of class WP_Error could not be converted to string in /usr/home/lloretensejove.cat/web/wp-content/themes/generatepress-child/functions.php on line 129
This is line 129:
echo '<li><a style="color: white !important;" href="' . get_term_link( $pterm->name, $taxonomyName ) . '">' . $pterm->name . '</a></li>';
I don't know how to fix this error.
I solved this error just changing this $pterm->name to this $pterm->term_id on the line:
echo '<li><a style="color: white !important;" href="' . get_term_link( $pterm->term_id, $taxonomyName ) . '">' . $pterm->name . '</a></li>';