get_search_link

函数
get_search_link ( $query = '' )
参数
  • (string) $query Optional. The query string to use. If empty the current query is used. Default empty.
    Required:
    Default: (empty)
返回值
  • (string) The search permalink.
定义位置
相关方法
get_search_feed_linkget_year_linkget_archives_linkget_term_linkget_self_link
引入
3.0.0
弃用
-

get_search_link函数是一个WordPress函数,用于检索搜索页面的URL: 这个函数接收一个搜索查询的可选参数并返回搜索页面的URL。

检索一个搜索的固定链接。

function get_search_link( $query = '' ) {
	global $wp_rewrite;

	if ( empty( $query ) ) {
		$search = get_search_query( false );
	} else {
		$search = stripslashes( $query );
	}

	$permastruct = $wp_rewrite->get_search_permastruct();

	if ( empty( $permastruct ) ) {
		$link = home_url( '?s=' . urlencode( $search ) );
	} else {
		$search = urlencode( $search );
		$search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded.
		$link   = str_replace( '%search%', $search, $permastruct );
		$link   = home_url( user_trailingslashit( $link, 'search' ) );
	}

	/**
	 * Filters the search permalink.
	 *
	 * @since 3.0.0
	 *
	 * @param string $link   Search permalink.
	 * @param string $search The URL-encoded search term.
	 */
	return apply_filters( 'search_link', $link, $search );
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-14 23:36:43

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: