我正在尝试自定义搜索查询,以便返回的项目按降序排列。我已经找到了产生结果的循环。。。。
global $wp_query;
$args = array(
\'post_status\' => \'publish\',
\'post_type\' => \'listings\',
\'meta_key\' => \'_ct_price\',
\'orderby\' => \'_ct_price\',
\'order\' => \'DESC\'
);
// save the existing query
$existing_query_obj = $wp_query;
$wp_query = new WP_Query( $args );
//$wp_query = new WP_Query( $search_values );
unset($search_values[\'post_type\']);
unset($search_values[\'paged\']);
unset($search_values[\'showposts\']);
/** Prepare the title string by looping through all
the values we\'re going to query and put them together */
$search_params = \'\';
$loop = 0;
foreach ($search_values as $t => $s) {
if ($loop == 1) {
$search_params .= \', \';
} else {
$loop = 1;
}
$term = get_term_by(\'slug\',$s,$t);
$name = $term->name;
$search_params .= \'<strong>\'. $name .\'</strong>\';
}
正如您所看到的,我在中添加了一个带有订购信息的$args部分,它目前不起作用,但如果我注释掉下面的行。。
$wp_query = new WP_Query( $args );
并取消对以下行的注释。。。。
$wp_query = new WP_Query( $search_values );
然后它确实可以工作,但忽略了其余的代码,有没有办法在不破坏现有查询的情况下将我的$args添加到现有查询中?