如何在woocommerce网址搜索结果上添加&post_type = product

时间:2019-03-05 13:18:24

标签: woocommerce woocommerce-theming

我有一个主题表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

谢谢

1 个答案:

答案 0 :(得分: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;
}

相关问题