Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpres ACF';post对象';和WooCommerce产品=首页错误?_Woocommerce - Fatal编程技术网

Wordpres ACF';post对象';和WooCommerce产品=首页错误?

Wordpres ACF';post对象';和WooCommerce产品=首页错误?,woocommerce,Woocommerce,我有这个问题: $query = new WP_Query( array( 'posts_per_page' => $postsCount, 'post_type' => 'events', 'taxonomy' => 'events-category', 'meta_key' => 'event-start-date', 'orderb

我有这个问题:

$query = new WP_Query(
        array(
            'posts_per_page' => $postsCount,
            'post_type' => 'events',
            'taxonomy' => 'events-category',
            'meta_key' => 'event-start-date',
            'orderby' => $postsOrderBy,
            'order' => $postsOrder,
            'meta_query' => array(
                array(
                        'key' => 'event-start-date',
                        'compare' => '>=',
                        'value' => date("Y-m-d"),
                        'type' => 'DATE',
                ),
            ),
        ),
    );
if ($query->have_posts()):
    while ($query->have_posts()): $query->the_post();
        // content
    endwhile;
    wp_reset_query();
endif;
在“内容”中,我有如下内容:

    <?php
    $post_object = get_field('event-ticket');
        if( $post_object ):
            $post = $post_object;
            setup_postdata( $post );
            $product->get_id(); ?>

    <div class="e-post__details-item e-post__details-item--event-price"><i class="e-post__details-item--icon fas fa-ticket-alt"></i><?php woocommerce_get_template( 'single-product/price.php' ); ?></div>

    <div class="l-cta l-cta--events">

    <div class="e-post__event-stock-status">
        <?php if ( $product->is_in_stock() ) {
        echo '<div class="e-post__event-stock-status-available">'.__('Dostępne!', 'woocommerce').'</div>';
        } elseif ( ! $product->is_in_stock() ) {
        echo '<div class="e-post__event-stock-status-unavailable">'.__('Wyprzedane!', 'woocommerce').'</div>';
        } ?>
    </div>

    </div>

    <?php
    wp_reset_postdata();
    endif;
    ?>

原因可能是什么?

您以前没有声明过
$product
。这就是为什么会出现这个错误<代码>$product->get_id()之前未初始化$product时

也许你首先想要:

$product = new WC_Product($post->ID);

我想:我只是添加了global$产品before$product->get_id();现在它开始工作了:)

我想:我只是添加了global$产品;在$product->get_id()之前;现在它开始工作了:)
$product = new WC_Product($post->ID);