Home Forums Front-end Issues ACF – Realtionship Field


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:

    $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(); ?>
    $posts = get_field('relationship_field_name');
    if( $posts ): ?>
        <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                <span>Custom field from $post: <?php the_field('author'); ?></span>
        <?php endforeach; ?>
        <?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,

Viewing 1 post (of 1 total)

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