首页 > 解决方案 > Wordpress 中的自定义产品搜索 URL

问题描述

嗨,我已经尝试了以下代码,似乎确实有效,并更改了关键字“holi”的常规搜索 url

https://www.englishbix.com/search/?s=holi&post_type=producthttps://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' );

我想要的结果

我用上面的代码得到的结果

标签: wordpresshook-woocommerce

解决方案


推荐阅读