get_search_template

Definition:
function get_search_template() {}

Retrieve path of search template in current or parent template.

Source code

function get_search_template() {

	return get_query_template('search');

}

1679

get_search_query

Definition:
function get_search_query( $escaped = true ) {}

Retrieve the contents of the search WordPress query variable.
The search query string is passed through esc_attr() to ensure that it is safe for placing in an html attribute.

Parameters

  • bool $escaped: Whether the result is escaped. Default true. Only use when you are later escaping it. Do not use unescaped.

Defined filters

  • get_search_query
    apply_filters( 'get_search_query', get_query_var( 's' )

Source code

function get_search_query( $escaped = true ) {

	$query = apply_filters( 'get_search_query', get_query_var( 's' ) );

	if ( $escaped )

		$query = esc_attr( $query );

	return $query;

}

1677

get_search_link

Definition:
function get_search_link( $query = '' ) {}

Retrieve permalink for search.

Parameters

  • string $query: Optional. The query string to use. If empty the current query is used.

Defined filters

  • search_link
    apply_filters( 'search_link', $link, $search )

Source code

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 unencoded.

		$link = str_replace( '%search%', $search, $permastruct );

		$link = home_url( user_trailingslashit( $link, 'search' ) );

	}



	return apply_filters( 'search_link', $link, $search );

}

1675

get_search_form

Definition:
function get_search_form($echo = true) {}

Display search form.
Will first attempt to locate the searchform.php file in either the child or the parent, then load it. If it doesn’t exist, then the default search form will be displayed. The default search form is HTML, which will be displayed. There is a filter applied to the search form HTML in order to edit or replace it. The filter is ‘get_search_form’.

Parameters

  • boolean $echo: Default to echo and not return the form.

Defined filters

  • get_search_form
    apply_filters('get_search_form', $form)
  • get_search_form
    apply_filters('get_search_form', $form)

Defined actions

  • get_search_form
    do_action( 'get_search_form' );

Source code

function get_search_form($echo = true) {

	do_action( 'get_search_form' );



	$search_form_template = locate_template('searchform.php');

	if ( '' != $search_form_template ) {

		require($search_form_template);

		return;

	}



	$form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '" >

	<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>

	<input type="text" value="' . get_search_query() . '" name="s" id="s" />

	<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />

	</div>

	</form>';



	if ( $echo )

		echo apply_filters('get_search_form', $form);

	else

		return apply_filters('get_search_form', $form);

}

1673

get_search_feed_link

Definition:
function get_search_feed_link($search_query = '', $feed = '') {}

Retrieve the permalink for the feed of the search results.

Parameters

  • string $search_query: Optional. Search query.
  • string $feed: Optional. Feed type.

Defined filters

  • search_feed_link
    apply_filters('search_feed_link', $link, $feed, 'posts')

Source code

function get_search_feed_link($search_query = '', $feed = '') {

	global $wp_rewrite;

	$link = get_search_link($search_query);



	if ( empty($feed) )

		$feed = get_default_feed();



	$permastruct = $wp_rewrite->get_search_permastruct();



	if ( empty($permastruct) ) {

		$link = add_query_arg('feed', $feed, $link);

	} else {

		$link = trailingslashit($link);

		$link .= "feed/$feed/";

	}



	$link = apply_filters('search_feed_link', $link, $feed, 'posts');



	return $link;

}

1671