Support

Account

Home Forums General Issues Retrieve specific Post Object's based on custom field Reply To: Retrieve specific Post Object's based on custom field

  • Hi @scferg

    The issue is 100% using wp_reset_postdata().

    This function will reset the query back to the origional one set by WP, not the one on line 5! This is very important to understand.

    You will need to not use the wp_reset_postdata(). This is easy, just make use of the get functions like so:

    
     <?php
    $post_object = get_field('person_company'); // Person's company Post Object field
    if( $post_object ):
    
            $company_name = get_the_title( $post_object->ID ); // Set company name from the person's company
            $company_link = get_field('company_link', $post_object->ID); // Set website url for the person's company
    
    ?>
    <p>
     
    	<?php the_field('person_title'); // Custom field from the person post ?>
    
    	<a href="<?php echo $company_link; ?>" target="_blank"><?php echo $company_name; ?></a>
    
    </p>
    
    <?php endif; ?>