• aliecoco

    (@aliecoco)


    I have several problem when trying to display data. I’m kind of new to this plugin and have already contacted your support but you never get back to me… Is anything wrong with the code ?

    Here are three examples :

    1. Trying to display post object data (doesn’t display anything on front-end)

    Response from debug:

    
    array(1) { [0]=> object(WP_Post)#19823 (24) { ["ID"]=> int(5540) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2020-05-11 16:41:54" ["post_date_gmt"]=> string(19) "2020-05-11 14:41:54" ["post_content"]=> string(0) "" ["post_title"]=> string(23) "FM : BCP Généralités" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(18) "fm-bcp-generalites" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2020-05-18 11:36:06" ["post_modified_gmt"]=> string(19) "2020-05-18 09:36:06" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(64) "http://localhost:8888/wordpress/?post_type=lp_course&p=5540" ["menu_order"]=> int(0) ["post_type"]=> string(9) "lp_course" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } }
    

    My code:

    
    <?php
    $post_objects = get_field('selection_des_fiches_pedagogiques');
    
    if( $post_objects ): ?>
        <ul>
        <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
                <span>Durée : <?php the_field('duree'); ?></span>
        <?php endforeach; ?>
        </ul>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif;
    ?>
    
            <?php
          endwhile;
          wp_reset_postdata();
        ?>
    

    2. Trying to display terms, shows array instead of value in front :

    
    array(1) {
      [0]=>
      int(250)
    }
    

    My code:

    
    <?php 
    $terms = get_field('supportsformation');
    if( $terms ): ?>
        <ul>
        <?php foreach( $terms as $term ): ?>
         <p> <?php echo esc_html( $term->name ); ?></p>
            <p><?php echo esc_html( $term->description ); ?></p>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    

    3. Post object data, array shows this and not display name like I need :

    
    Arrayarray(1) { [0]=> array(11) { ["ID"]=> int(24) ["user_firstname"]=> string(4) "Marc" ["user_lastname"]=> string(8) "Gangloff" ["nickname"]=> string(12) "FormateurDOF" ["user_nicename"]=> string(12) "formateurdof" ["display_name"]=> string(12) "FormateurDOF" ["user_email"]=> string(20) "[email protected]" ["user_url"]=> string(0) "" ["user_registered"]=> string(19) "2020-05-12 15:13:09" ["user_description"]=> string(0) "" ["user_avatar"]=> string(259) "" } }
    

    My code:

    
    <?php
    	$posts = get_field('sessions_a_venir');
    	if($posts): 
    ?>
    <ul>
    	<?php 
    		foreach( $posts as $post): // ne pas changer $post IMPORTANT
    			setup_postdata($post);
    			$event_id = get_the_id(); 
    			
    	?>
    
    	<li>
    		<a href="<?php the_permalink(); ?>">
    		<b>Date :</b> <?php echo tribe_get_start_date(); ?> - <b>Lieu</b> : <?php echo tribe_get_venue(); ?> - <b>Formateur :</b>
    		
    		<?php echo
    $user = get_field('formateur');
    if( $user ): ?>
        <h3><?php echo $user['display_name']; ?></h3>
       
        <?php endif; ?>
    
    	
    		
    		<?php echo rtec_attendance_count_display( $event_id, '<b>Inscrits :</b> {num} sur {max}' ); ?>	</a>
    	</li>
    	<?php endforeach; ?>
    </ul>
    
    <?php 
    		wp_reset_postdata(); // IMPORTANT - réinitialiser l'objet $post sur la requête principale
    ?>
    
    <?php else: // field_name returned false ?>
    <span>Aucune session n'est prévue pour cette formation.</span>
    <?php endif; // end of if field_name logic ?>`
    
    

The topic ‘Data not displaying’ is closed to new replies.