WordPress输出搜索关键词标签:the_search_query

WordPress模板标签the_search_query用于输出搜索关键词,通常用在搜索表单和搜索结果页中。

the_search_query()

该函数没有任何参数,直接调用即可。

the_search_query()函数使用示例

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
	<div>
		<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
		<input type="submit" id="searchsubmit" value="Search" />
	</div>
</form>

  在结果页面显示搜索查询,你可以在搜索结果页面显示搜索字符串

You searched for " <?php echo esc_html( get_search_query( false ) ); ?> ". Here are the results:

扩展阅读

the_search_query()函数位于:wp-includes/general-template.php

参考:https://www.beizigen.com/1827.html