Home › Forums › General Issues › Use post object in a loop of a custom post type › Reply To: Use post object in a loop of a custom post type
Hi,
I had the same problem.
I made a loop on CPT and in each one I need a post-objet.
Here is what i made
<table>
<tr>
<td>Nom/Prénom</td><td>Numéro de téléphone</td><td >email</td><td>Commission</td>
</tr>
<?php while($author_posts_contacts->have_posts()) : $author_posts_contacts->the_post();?>
<tr>
<td> <?php $id_post_origine=get_the_ID();?>//Register the "parent" post id
<strong><?php the_field('titre_du_post'); ?> <?php the_field('nom_correspondant_festo'); ?></a></strong></br>
<?php $post_object = get_field('structure'); if( $post_object ): $post = $post_object; setup_postdata( $post ); ?>//Call the post object Inside and work with
(<?php the_title(); ?>)
<?php $post = $id_post_origine; setup_postdata( $post ); ////Call back the "parent" post datas
endif; ?>
</td>
<td><?php the_field('numero_de_telephone_correspondant_festo'); ?></td>
<td><?php the_field('email_correspondant_festo'); ?></td>
<td><?php $mots_cles = get_field('commission_correspondant_festo');
foreach ($mots_cles as $mot_cle):
$id_du_mot_cle = get_term( $mot_cle);
echo $id_du_mot_cle->name.'</br>';
endforeach;?>
</td></tr>
<?php
endwhile;?></table>
I hope this helps.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.