Support Forum
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?
From the error above, I guess the problem isn't the code. Probably one of the selected term was deleted or not available. That's why it returns an WP_Error
object. Please check that.
The terms are all in the DB. Every thing looks like in the working taxonomies. I did delete this taxonomiy some time ago and made it new. But even if I create new taxonomies it does not work anymore. Allways the same errors as above.
I have no idea where to check it.
Puh, lots of troubles with these plugins. When I change from Select to Checkbox List in the Metabox Tab Plugin and when I add a term to a taxonomy I get "Catchable fatal error: Object of class WP_Term could not be converted to string" in the frontend. The error even keeps showing when I go back...
What can I do?
...other situation. By choosing Field Type "Select" I get “Catchable fatal error: Object of class WP_Term could not be converted to string” in the frontend. By coosing Field Type "Select Tree" it works as expected.
You mean when changing field_type
, the returned value changes? Can you post the code to register this field to check? Thanks.
I made everything with the plugins. Is there a possibility to see or extract the code?
Is there a possibility to see or extract the code?
Maybe just use var_dump
or print_r
?
If you don't mind, please give me the post to register meta boxes. I can check that for you.
Thank you very much. I'll send you more info by your contact form on https://metabox.io/contact/