【发布时间】:2019-03-05 13:18:24
【问题描述】:
我有一个主题表单 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 …', 'placeholder'), 'value' => get_search_query()], 'name' => get_post_type()]
]
]);
if ($echo) {
echo $result;
} else {
return $result;
}
我跪下来修改此代码并将 &post_type=product 添加到结果 url
谢谢
【问题讨论】:
-
您只想要搜索中的产品吗?还是页面和帖子以及所有东西?
-
是的,只有产品!搜索后的网址是:example.com/?s=test(此代码如下)我跪为:example.com/?s=test&post_type=product(此代码修改)谢谢
-
如果你只想要产品,你只需要URL中的post_type GET参数
标签: woocommerce woocommerce-theming