0

我有一个主题表单 yootheme pro,我在 searchform.php 上有以下代码:

<?php
/**
 * The template for displaying a search form.
 */

$result = get_view('search', [

    'position' => get_current_sidebar(),
    'attrs' => [

        'id' => 'search-'.rand(100, 999),
        'action' => esc_url(home_url('/')),
        'method' => 'get',
        'role' => 'search',
        'class' => '',

    ],
    'fields' => [

        ['tag' => 'input', 'name' => 's', 'placeholder' => esc_attr_x('Search &hellip;', 'placeholder'), 'value' => get_search_query()], 'name' => get_post_type()]

    ]

]);

if ($echo) {
    echo $result;
} else {
    return $result;
}

我跪下来修改这个编码并将 &post_type=product 添加到结果 url

谢谢

4

1 回答 1

0

试试这个。不确定这是否适用于您的模板,但在我的模板中可以。所以只是为了澄清:WordPress中有许多不同的帖子类型。例如页面、产品使用...

我们所知道的是告诉函数它应该采用哪种搜索值。逻辑上它应该工作!

<?php
/**
 * The template for displaying a search form.
 */

$result = get_view('search', [

    'position' => get_current_sidebar(),
    'attrs' => [

        'id' => 'search-'.rand(100, 999),
        'action' => esc_url(home_url('/')),
        'method' => 'get',
        'role' => 'search',
        'class' => '',

    ],
    'fields' => [

        ['tag' => 'input', 'name' => 's', 'placeholder' => esc_attr_x('Search &hellip;', 'placeholder'), 'value' => 'product'], 'name' => 'post_type']

    ]

]);

if ($echo) {
    echo $result;
} else {
    return $result;
}

于 2019-03-07T13:29:34.150 回答