如果要使用Wp_Query 要从数据库中选择单个产品,必须通过p 在$args 因此,如果获取数据post_type 应为product.
跟进正常情况$args 方法,您必须添加以下代码行。
<?php
$params = array(
\'p\' => \'YOUR PRODUCT ID\', id of a page, post, or custom type
\'post_type\' => \'product\'
);
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) : $wc_query->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( \'No Product\' ); ?></p>
<?php endif; ?>