I’m trying to display a Custom Post Type (CPT) called ‘affichage_produit’ on the front page of my WordPress site. Each ‘affichage_produit’ post has an Advanced Custom Fields (ACF) ‘Post Object’ field linking it to a WooCommerce product, and a ‘Text Area’ field for key points.
I’ve added the following code to my front-page.php file to query the ‘affichage_produit’ posts and display the product data and key points:
<?php
$args = array(
'post_type' => 'affichage_produit',
'posts_per_page' => 2,
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product_id = get_field('associated_product');
$product = wc_get_product($product_id);
$points_forts = get_field('points_forts');
// Display the product data and key points here
if ($product) {
echo '<h2>' . $product->get_name() . '</h2>';
echo '<p>Price: ' . wc_price($product->get_price()) . '</p>';
echo '<p>Points Forts: ' . $points_forts . '</p>';
}
}
wp_reset_postdata();
}
?>
However, nothing is being displayed on the front page. I’ve confirmed that I have ‘affichage_produit’ posts and that they have the ‘associated_product’ and ‘points_forts’ fields set.
Any ideas why the ‘affichage_produit’ posts and their associated data are not being displayed?
I’ve also enabled WP_DEBUG but I’m not seeing any PHP errors.