我不再需要WooCommerce,我正在将所有woocommerce产品转换/转换为wordpress帖子。我使用过Post Type Switcher插件,但这不是我需要的。我需要转换所有产品属性和详细信息,并在帖子页面中显示它们。我该怎么做?
答案 0 :(得分:0)
您可以尝试这样的事情:
<?php
// Setup your query
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'type', //Custom attribute
'field' => 'slug',
'terms' => 'custom_type',
),
array(
'taxonomy' => 'color', //Custom attribute
'field' => 'slug',
'terms' => 'orange',
),
array(
'taxonomy' => 'size', //Custom attribute
'field' => 'slug',
'terms' => 'medium',
),
),
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
//Get specific meta data from product
$product = get_product($loop->post);
?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>">
<?php the_title(); ?>
</a>
<!-- color attribute of product -->
<p class="color">Color of product: <?php echo $product->get_attribute('color'); ?></p>
<!-- size attribute of product -->
<p class="size">Size of product: <?php echo $product->get_attribute('size'); ?></p>
<!-- color attribute of product -->
<p class="type">Category: <?php echo $product->get_attribute('type'); ?></p>
<?php endwhile; wp_reset_query(); // Remember to reset
?>
根据您的属性等,它显然会有所不同。