douzhu3367 2019-05-14 15:57
浏览 20

获取Post Object WooCommerce产品变化的ID

The title of the post actually says everything. I am trying to retrieve an ID from a WooCommerce product variation but it does not show anything.

I made a Custom Field - Post Object with:

Filter on post type: Product

Filter on Taxonmy: Product property

Working fine when selecting in a page but when I try to get the ID in template... Nothing.

Well not nothing because he is getting the ID of its parent. So the main product got ID 98, and two variations got 99 and 100. I need to get the ID of the variation because that is the field I selected.

How can I get the variation ID of the Post Object and not the ID of the main product?

I already searched in Google but no luck yet, also tried the documentation of Advanced Custom Fields but no luck either.

<?php

$post_object = get_field('post_object');

if( $post_object ): 

    // override $post
    $post = $post_object;
    setup_postdata( $post ); 

    ?>
    <div>
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <span>Post Object Custom Field: <?php the_field('field_name'); ?></span>
    </div>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看