Home › Forums › General Issues › Object Post
I have a custom field of type object post me and in them the post type product is selected, how do I return the product image and the product price?
I’m using the loop that the site provides
<?php
$featured_posts = get_field(‘featured_posts’);
if( $featured_posts ): ?>
ul
<?php foreach( $featured_posts as $featured_post ):
$permalink = get_permalink( $featured_post->ID );
$title = get_the_title( $featured_post->ID );
$custom_field = get_field( ‘field_name’, $featured_post->ID );
?>
li
“><?php echo esc_html( $title ); ?>
<span>A custom field from this post: <?php echo esc_html( $custom_field ); ?></span>
/li
<?php endforeach; ?>
/ul
<?php endif; ?>

You did not use code tags so I can not see all of the code. But from what I can see it is correct. What is your question?
I would like to know what would be the variable to get the product image and the price, in the current code I only have the product title variable

If they are ACF fields
$custom_field = get_field('field_name', $featured_post->ID);
if they are fields associated with something else, like WooCommerce then you will need to refer to their documentation for getting these values.
yes woocommerce fields, but the variables from their documentation don’t work inside the loop I’m using
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.