Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为搜索查询wordpress添加额外参数_Php_Wordpress - Fatal编程技术网

Php 为搜索查询wordpress添加额外参数

Php 为搜索查询wordpress添加额外参数,php,wordpress,Php,Wordpress,这是我的密码: global $query_string; $posts = query_posts($query_string . '&orderby=meta_value_num&order=DESC&posts_per_page=-1&meta_key=post_views_count'); while (have_posts()) : the_post(); endwhile; 这段代码在分类法归档页面中有效,但在search.php中无效,没

这是我的密码:

global $query_string;
$posts = query_posts($query_string . '&orderby=meta_value_num&order=DESC&posts_per_page=-1&meta_key=post_views_count');
while (have_posts()) : the_post();    

endwhile;
这段代码在分类法归档页面中有效,但在search.php中无效,没有搜索结果。我的代码有什么问题?我只想为搜索结果添加排序。

请尝试以下代码:

<?php
global $query_string;
query_posts($query_string . '&orderby=meta_value_num&order=DESC&posts_per_page=-1&meta_key=post_views_count');
while (have_posts()) : the_post();    

endwhile;
wp_reset_query();
?>