我正在尝试使用WP_Query在Wordpress中通过其ID获取特定产品,并且我很难从昨天找到正确的参数。我被卡住了。来自'product_cat'分类法
$args = array(
'post_type' => 'product',
'posts_per_page' => 1,
'id' => $product_id,
);
答案 0 :(得分:2)
$args = array(
'post_type' => 'product',
'posts_per_page' => 1,
'post__in'=> array($product_id)
);
答案 1 :(得分:0)
愚蠢的探索,但我找到了答案。让我的大脑挣扎了这么久......
$args = array(
'post_type' => 'product',
'posts_per_page' => 1,
'post__in'=> array($id),
);
答案 2 :(得分:0)
function cs_get_cost_transportation( WP_REST_Request $request ) {
$productId = $request->get_param( 'productId' );
$wpq = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 1,
'post__in'=> array($productId)
) );
$postIds = $wpq->get_posts();
$productsFilter_cabin = cs_get_products_for_from_post_ids( $postIds );
return rest_ensure_response($productsFilter_cabin);
}