• I need to display a custom field from the parent connected post. It’s easier to describe through the code:

    $connected = new WP_Query( array(
    	  'connected_type' => 'programs_to_facilities',
    	  'connected_items' => get_queried_object(),
    	  'nopaging' => true,
    	) );
    
    	// Display connected facility
    	if ( $connected->have_posts() ) : ?>
    			<div class="facility">
    			<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    				<address>
    					<?php the_field('facility_address'); ?>,
    					<?php the_field('facility_city'); ?> OH
    					<?php the_field('facility_zip'); ?> •
    					<?php the_field('program_main_phone'); ?>
    				</address>
    			<?php endwhile; ?>
    			</div>
    		<?php
    		// Prevent weirdness
    		wp_reset_postdata();
    	endif;

    Where I have program_main_phone, that is from the parent connected post. In this case the Parent post is of post type ‘program’ and this code displays the connected ‘facility’ but I do need to display one field from the parent post. Is this possible?

    http://wordpress.org/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • J M

    (@hiphopinenglish)

    If you are showing this on a single template, get the custom field value you need OUTSIDE this loop:
    <?php $field = get_field($field_name, $post_id, $format_value); ?>
    Then echo $field; in the place in your template that it needs to be – inside the above loop if needs be.

Viewing 1 replies (of 1 total)
  • The topic ‘Display custom field from parent post’ is closed to new replies.