Support

Account

Home Forums Front-end Issues ACF – Realtionship Field

Unread

ACF – Realtionship Field

  • Hi, I created 2 CPT:

    • Case Studies;
    • Clients

    For each client I want to add one ore more case studies. So I created a “Relation” Field. My PHP code for the page: archive-clients.php is:

    <?php
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'clienti',
    
    );
    
    // query
    $the_query = new WP_Query( $args );
    ?>					
    
    <?php if( $the_query->have_posts() ): ?>
    	<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php 
    
    $posts = get_field('relationship_field_name');
    
    if( $posts ): ?>
        <ul>
        <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                <span>Custom field from $post: <?php the_field('author'); ?></span>
            </li>
        <?php endforeach; ?>
        </ul>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>
    
    <?php endwhile; ?>
    <?php endif; ?>	
    

    But nothing is display, why?
    Can someone help me, please?

    Best Regards,
    Roebrto

Viewing 1 post (of 1 total)

The topic ‘ACF – Realtionship Field’ is closed to new replies.