How to display in front end
- This topic has 8 replies, 2 voices, and was last updated 8 years, 5 months ago by
Lufrutta.
-
AuthorPosts
-
November 18, 2016 at 4:22 AM #4502
Lufrutta
ParticipantI 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 MB 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-tag0264pflege01rawWhat do I wrong?
November 18, 2016 at 10:17 AM #4503Anh Tran
KeymasterFrom 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.November 18, 2016 at 2:36 PM #4506Lufrutta
ParticipantThe 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.
November 18, 2016 at 10:16 PM #4509Lufrutta
ParticipantPuh, 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?
November 19, 2016 at 12:28 AM #4510Lufrutta
Participant...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.
November 19, 2016 at 9:30 AM #4515Anh Tran
KeymasterYou mean when changing
field_type
, the returned value changes? Can you post the code to register this field to check? Thanks.November 19, 2016 at 3:39 PM #4516Lufrutta
ParticipantI made everything with the plugins. Is there a possibility to see or extract the code?
November 22, 2016 at 4:16 PM #4532Anh Tran
KeymasterIs there a possibility to see or extract the code?
Maybe just use
var_dump
orprint_r
?If you don't mind, please give me the post to register meta boxes. I can check that for you.
November 22, 2016 at 8:43 PM #4533Lufrutta
ParticipantThank you very much. I'll send you more info by your contact form on https://metabox.io/contact/
-
AuthorPosts
- You must be logged in to reply to this topic.