wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_search_link › WordPress Function

Seit3.0.0
Veraltetn/v
get_search_link ( $query = '' )
Parameter:
  • (string) $query Optional. The query string to use. If empty the current query is used. Default empty.
    Erforderlich: Nein
    Standard: (leer)
Gibt zurück:
  • (string) The search permalink.
Definiert in:
Codex:

Retrieves the permalink for a search.



Quellcode

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 );
}