运行查询之前,需要更改查询设置。我假设你有search.php
第页,但如果没有,我会告诉你在最后把代码放在哪里。
在里面search.php
将其添加到文件的最顶部(位于get_header()
电话)-
$args = array(
\'posts_per_page\' => get_option(\'posts_per_page\'),
\'paged\' => $paged,
\'post_type\' => $post_type, // The post type that you wish to search
$taxonomy => $term // Where $taxonomy is say \'cheese\' and $term (must use the slug) is maybe \'cheddar\'. Can be omitted if you do not actually wish to search taxonomy/terms. I think you can also pass $term as an array of terms - array(\'cheddar\', \'brie\', \'edam\').
);
如果您没有
search.php
, 按如下所示嵌套代码,并将其放置在
index.php
文件-
if(is_search()) :
{ Code from above goes here }
endif;