Php 在木材中,文件准备在哪里搜索查询?

Php 在木材中,文件准备在哪里搜索查询?,php,twig,timber,Php,Twig,Timber,在搜索表单中,搜索参数由GET发送 http://site_url/?s=searching_text 如何准备sql查询或文件在哪里准备查询 在细枝中搜索表单: {% block searchform %} <form role="search" method="get" class="search-form form" action="{{ site.url }}/"> <label> <span class=

在搜索表单中,搜索参数由GET发送

http://site_url/?s=searching_text
如何准备sql查询或文件在哪里准备查询

在细枝中搜索表单:

{% 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 %}
{%block searchform%}
{{{{{('搜索:','g5}}

{%endblock%}
该文件在逻辑上命名为search.php,其外观如下:

$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);
以防在搜索结果中使用分页。
这里的结果来自“posts”,但也来自一个名为“products”的自定义post类型,但您可以随意自定义该查询。

您正在查看一个模板。实际执行搜索的代码将在php文件中。