当你跑步时get_post_meta( get_the_ID(), \'_crosssell_ids\',true);
您将获得当前产品交叉销售给的所有产品的数组。
我该如何扭转这种局面?要获取交叉销售到当前项目的所有产品?
示例:
不是这个:产品1->交叉销售:产品2,产品3
但这个:产品3<;-交叉销售:产品1
当你跑步时get_post_meta( get_the_ID(), \'_crosssell_ids\',true);
您将获得当前产品交叉销售给的所有产品的数组。
我该如何扭转这种局面?要获取交叉销售到当前项目的所有产品?
示例:
不是这个:产品1->交叉销售:产品2,产品3
但这个:产品3<;-交叉销售:产品1
可以通过元查询来实现
$current_post_id = \'YOUR_POST_ID\';
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
array(
\'key\' => \'_crosssell_ids\',
\'value\' => $current_post_id,
\'compare\' => \'LIKE\'
)
)
);
$query = new WP_Query($args);
if($query->have_posts()){
while($query->have_posts()): $query->the_post();
$product = wc_get_product(get_the_ID());
// Do what you want with the product.
endwhile;
}
此查询将返回所有具有$current\\u post\\u id作为交叉销售id的产品。希望这有帮助。
实际上,我正在为我的博客构建一个自定义主题,我在HTML中使用单引号,如:<div class=\'div\'></div> 这是否会导致我重定向到索引。php??我的网站在301处正确重定向,mod\\u rewrite已启用,并响应链接但打开索引。php。这是因为我使用了单引号吗??