使用新参数筛选/重新排序现有WP查询



我试图限制页面上调用的查询数量,并在不同区域显示两个类似的arg集:

$recent_args = array(
'post_type' => 'post',
'cat' => 941,
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC'
);
$trending_args = array(
'post_type' => 'post',
'cat' => 941,
'posts_per_page' => 12,
'meta_key' => 'custom_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);

我怎么能只执行一次这个查询,但在实际显示中根据不同的参数重新排序?

请使用类似的if else条件

$data = 1;
if($data == 1)
{
$args = array(
'post_type' => 'post',
'cat' => 941,
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC'
);
}
else
{
$args = array(
'post_type' => 'post',
'cat' => 941,
'posts_per_page' => 12,
'meta_key' => 'custom_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
}
$query_result = new WP_Query($args);

最新更新