【发布时间】:2023-01-14 05:58:15
【问题描述】:
我正在制作一个新的 WP_Query 来搜索产品。
这向我显示了 wp_post 信息,但没有显示股票信息。
如何在搜索中将库存结果排在最前面,将非库存结果排在最后。
这是我当前的代码。
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
's' => $filter_name,
'tax_query' => $tax_query,
'posts_per_page'=> $limit
);
$list = new WP_Query( $args );
试试这个代码,但它不起作用
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
's' => $filter_name,
'tax_query' => $tax_query,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => '_stock',
'posts_per_page'=> $limit
);
$list = new WP_Query( $args );
【问题讨论】:
标签: php wordpress woocommerce