我有这个代码
<?php
$dateTimeStart = new DateTime(tribe_get_start_date( null, false, 'Y-m-d' ));
$dateTimeEnd = new DateTime(tribe_get_start_date( null, false, 'Y-m-d' ));
$bookings = WC_Bookings_Controller::get_bookings_in_date_range(
$dateTimeStart->getTimestamp(),
$dateTimeEnd->getTimestamp(),
'',
false
);
$booked[] = 0;
foreach ($bookings as $booking) {
$booked[] = $booking->product_id;
}
$args = array (
'post__in' => $booked,
'post_type' => ['product'],
);
$query = new WP_Query( $args );
$posts = $query->posts;
$sku = $product->get_sku();
wp_reset_query();
?>
从上述查询中提取 SKU 的正确方法是什么?
我试过
<?php echo esc_html( get_post_meta( get_the_ID(), '_sku', true ) ); ?>
哪个适用于此查询
<?php
$args = array( 'post_type' => 'product', 'terms' => array('fvip-ddb','fvip-sdb'), 'posts_per_page' => -1, 'meta_key' => '_regular_price' );
$loop = new WP_Query( $args );
$sku = get_post_meta( $item['product_id'], '_sku', true );
?>
但第一个查询不起作用(显示空白)
更新
使用下面的代码,当我运行它时:
<?php foreach($posts as $post) { echo "{ toolTip: \"Say something here.\", key : \"$skubooked\", staticState: true },"; } ?>
由于某种原因,循环返回相同的值 3 次。(有三个不同的产品预订..但循环显示相同的产品三次)..