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