2015-02-23 63 views
0

,所以我查询职位。但我有我的产品已在wooCommerce中创建的自定义属性,但我无法在任何地方找到此信息。访问woocomerce产品属性使用query_posts

我试着使用:

$thePost = get_post_custom() 

我也尝试:

$thePost = get_post_meta(get_the_ID) 

当我print_r的这些我得到了很多的信息,但我不能看到产品从woocommerce随时随地

属性下面的图片显示了如何在产品上设置此信息。

enter image description here

有谁知道我如何访问查询后门柱的信息? 具体而言,我需要提取颜色和大小。

回答

1

产品变体保存为另一个子帖子(自定义帖子类型product_variation)。以下代码未经测试,但您应该明白。

query_posts('post_type=Product&showposts=-1'); 
while(have_posts()){ 
    the_post(); 
    $product_id = get_the_ID(); 

    $variations = get_posts(array('post_type' => 'product_variation', 'post_parent' => $product_id, 'posts_per_page' => -1)); 

    foreach($variations as $var){ 
    $var_customs = get_post_customs($var->ID); 
    // now you can inspect "meta" fields 
    } 
} 

所以,你必须与产品ID = 7 - >post_type=product,它的变化是post_type=product_variation&post_parent=7。尺寸和库仑被保存为这些变化的元值。元键从attribute_pa_...开始。