How to display in front end

Support General How to display in front end

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #4502
    LufruttaLufrutta
    Participant

    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 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-tag0264pflege01raw

    What do I wrong?

    #4503
    Anh TranAnh Tran
    Keymaster

    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.

    #4506
    LufruttaLufrutta
    Participant

    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.

    #4509
    LufruttaLufrutta
    Participant

    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?

    #4510
    LufruttaLufrutta
    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.

    #4515
    Anh TranAnh Tran
    Keymaster

    You mean when changing field_type, the returned value changes? Can you post the code to register this field to check? Thanks.

    #4516
    LufruttaLufrutta
    Participant

    I made everything with the plugins. Is there a possibility to see or extract the code?

    #4532
    Anh TranAnh Tran
    Keymaster

    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.

    #4533
    LufruttaLufrutta
    Participant

    Thank you very much. I'll send you more info by your contact form on https://metabox.io/contact/

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.