Query_posts $query_string

时间:2017-07-31 作者:Josh Rodgers

我有一个如下查询:

query_posts($query_string."&post_type=attachment&posts_per_page=9&paged=".$paged);

我希望它看起来像:

$args = array(
    \'paged\' => $paged,
    \'posts_per_page\' => 9,
    \'post_type\' => \'attachment\'
);
query_posts($args);
我正在尝试整合$query_string 进入query_posts 具有$args...谁能给我指出正确的方向吗。

谢谢,乔希

1 个回复
最合适的回答,由SO网友:Josh Rodgers 整理而成

经过一些搜索,我找到了所需的参数:https://gist.github.com/luetkemj/2023628 (第231行)

//////Search Parameter
//http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter
\'s\' => $s,                              //(string) - Passes along the query string variable from a search. For example usage see: http://www.wprecipes.com/how-to-display-the-number-of-results-in-wordpress-search 
\'exact\' => true,                        //(bool) - flag to make it only match whole titles/posts - Default value is false. For more information see: https://gist.github.com/2023628#gistcomment-285118
\'sentence\' => true,                     //(bool) - flag to make it do a phrase search - Default value is false. For more information see: https://gist.github.com/2023628#gistcomment-285118
我补充道\'s\' => $s 给我的$args 它沿着查询字符串传递,这就是我要查找的内容:-)

我的代码现在看起来像:

$args = array(
    \'paged\' => $paged,
    \'posts_per_page\' => 9,
    \'post_type\' => \'attachment\',
    \'s\' => $s
);
query_posts($args);

结束

相关推荐