WP_Error 在短代码中显示术语

WP_Error in a shortcode to show terms

我正在使用 Anywhere Elementor 设计分类存档模板。我用这个简码来显示所有术语

// 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' );

在我尝试翻译此页面之前,它一直运行良好。 WordPress 给我这个错误:

 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 

这是第 129 行:

echo '<li><a style="color: white !important;" href="' . get_term_link( $pterm->name, $taxonomyName ) . '">' . $pterm->name . '</a></li>';

我不知道如何解决这个错误。

我解决了这个错误,只是将此 $pterm->name 更改为此 $pterm->term_id 行:

echo '<li><a style="color: white !important;" href="' . get_term_link( $pterm->term_id, $taxonomyName ) . '">' . $pterm->name . '</a></li>';