wordpress - Wordpress 中的自定义产品搜索 URL
问题描述
嗨,我已经尝试了以下代码,似乎确实有效,并更改了关键字“holi”的常规搜索 url
https://www.englishbix.com/search/?s=holi&post_type=product到https://www.englishbix.com/search/holi/
但它使用默认搜索模板来显示产品搜索结果,而不是使用 woocommerce 搜索结果模板。
//change the url to static slug instead of dynamic one
function wpb_change_search_url() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'wpb_change_search_url' );
解决方案
推荐阅读
- mongodb - 如何使用 ubuntu 中的所有实例完全删除 mongoDB
- css - 移动设备的视频 CSS 问题
- robotframework - If else 在机器人框架中循环
- jekyll - 如何限制 Jekyll 博客主页上显示的行数?
- java - Java:一次只切换 1 个单选按钮(RecyclerView)
- iframe - IFrame 未检测到 CSS
- r - 数列中相同值的计数频率
- android - 检查互联网是否可用(targetSdk:Android Q)
- java - 如果缓存服务器失败,是否可以让应用程序忽略缓存?
- javascript - 我们如何确保每个 UI 元素的唯一标识符,以便我的 QA 团队可以在自动化测试时捕获任何 DOM 元素?