
Hi,
I’m trying to get the Email field to my Product post type from a related Seller post type Email field.
I have two post types Seller and Product.
Seller post type has custom fields:
- Bi-directional relationship field to Products so seller is linked to products
- Email field
- Telephone, address etc…
Product post type with fields:
- Bi-directional relationship field to Seller
- Email field (I would like this to fetched from the related Seller post type)
- Additional product information etc…
I’ve looked at multiple examples about post relationships and fields but I haven’t found any examples on how to get a specific field from a related post and display/attach it to a post in the backend.
Any suggestions on where to start or is this even possible?
I think this might be a starting point.
https://support.advancedcustomfields.com/forums/topic/display-custom-field-value-from-another-post-type/
The only thing is that I don’t think this will work in the backend.
<?php
$post_object = get_field('project_name');
if( $post_object ): ?>
<div>
<h4><?php echo get_the_title($post_object->ID); ?></h4>
<span>Post Object Custom Field: <?php the_field('project_description', $post_object->ID); ?></span>
</div>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Hi olppa,
Have you found a solution for this problem?
Thanks.