is_search

函数
is_search ( No parameters )
返回值
  • (bool) Whether the query is for a search.
定义位置
相关方法
is_yearis_archiveis_archivedinstall_search_formis_term
引入
1.5.0
弃用
-

is_search: 这个函数检查当前页面是否是一个搜索结果页面。如果该页是搜索结果页,则返回true,否则返回false。

确定该查询是否为搜索。

关于这个和类似主题功能的更多信息,请查看《主题开发者手册》中的{@link Conditional Tags}文章。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function is_search() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_search();
}
function is_search() { global $wp_query; if ( ! isset( $wp_query ) ) { _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); return false; } return $wp_query->is_search(); }
function is_search() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_search();
}

常见问题

FAQs
查看更多 >