I have a taxonomy with several entries. Its ID is "pflege". In the backend I can select one entry of this taxonomy (Field Type Select). It's all realised with Meta Box Tabs and looks great.
When I try to display it in the front end I use the following code:
<?php $terms = rwmb_meta( 'pflege' );
if ( !empty( $terms ) ) {
echo '<h2>Pflegeangebot</h2>';
$content = '<div class="angebotsliste"><ul>';
foreach ( $terms as $term ) {
$content .= sprintf(
'<li><a href="%s" title="%s">%s</a></li>',
get_term_link( $term, 'tax_slug' ),
$term->name,
$term->name
);
}
$content .= '</ul></div>';
echo $content;
} ?>
I get the following output in the frontend:
Pflegeangebot
Notice: Trying to get property of non-object in /var/www/vhosts/*****/httpdocs/betriebe/wp-content/themes/HKS2017/single-betriebe.php on line 117
Notice: Trying to get property of non-object in /var/www/vhosts/*****/httpdocs/betriebe/wp-content/themes/HKS2017/single-betriebe.php on line 118
Catchable fatal error: Object of class WP_Error could not be converted to string in /var/www/vhosts/*****/httpdocs/betriebe/wp-content/themes/HKS2017/single-betriebe.php on line 119
I have two other taxonomies where it works exactly this way without any problem.
So I tried to use the following code:
<?php $terms = rwmb_meta( 'pflege' );
if ( !empty( $terms ) ) {
echo '<h2>Pflege</h2>';
foreach ( $terms as $term ) {
echo $term;
}
} ?>
Now I get the following output in the frontend:
Pflege
264Leichte Pflegefälle (bis 30 Minuten pro Tag)leichte-pflegefaelle-bis-30-minuten-pro-tag0264pflege01raw
What do I wrong?