Reputation: 1408
In search form searching parameter is send by GET
http://site_url/?s=searching_text
How is preparing the sql query or where is the file preparing the query?
search form in Twig:
{% block searchform %}
<form role="search" method="get" class="search-form form" action="{{ site.url }}/">
<label>
<span class="screen-reader-text">{{ __('Search for:', 'g5_helium') }}</span>
<input type="search" class="search-field" placeholder="{{ __( 'Szukaj …', 'g5_helium' ) }}" value="" name="s" title="{{ __('Search for:', 'g5_helium') }}" />
</label>
<p></p>
<input type="submit" class="search-submit button button-small" value="Szukaj" />
</form>
{% endblock %}
Upvotes: 1
Views: 1111
Reputation: 73
The file is logically named search.php, it can look something like this :
$templates = array( 'search.twig', 'archive.twig', 'index.twig' );
$context = Timber::get_context();
$context['title'] = get_search_query();
$text_search = get_search_query();
$args = array(
'post_type' => array('post', 'product'),
'posts_per_page' => 8,
's' => $text_search,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'paged' => $paged
);
$context['pagination'] = Timber::get_pagination();
$context['posts'] = new Timber\PostQuery($args);
$context['count'] = new WP_Query($args);
Timber::render('templates/search.twig', $context);
That's in case you use pagination in search results. Here the results are from "posts" but also a custom post type called "products", but you can customize that query at will.
Upvotes: 4