Wordpress 使用 WP_Query 通过 ID 获取产品

sar*_*nos 2 wordpress

我正在尝试使用 WP_Query 在 Wordpress 中通过其 ID 获取特定产品,并且我正在努力从昨天开始寻找正确的论点。我被卡住了。我来自“product_cat”分类法

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 1,
    'id' => $product_id,
);
Run Code Online (Sandbox Code Playgroud)

小智 6

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 1,
    'post__in'=> array($product_id)
);
Run Code Online (Sandbox Code Playgroud)