【问题标题】:WordPress how to encode the searched URLWordPress 如何对搜索到的 URL 进行编码
【发布时间】:2021-01-23 13:16:48
【问题描述】:

我想让搜索 URL 看起来像这样:

example.com/search/search+query?post_type=product.

我尝试了很多方法,包括:

wp_redirect( home_url( "/search/?s=" ) . urlencode( get_query_var( 's' ) . "&post_type=" . urlencode( get_query_var( 'post_type' ) ) );

还有这个:

wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ). "?post_type=". urlencode( get_query_var( 'post_type' ) ) ) );

但我得到的结果:

example.com/search/search+query%3Fpost_type%3Dproduct

我该怎么办?

【问题讨论】:

    标签: php wordpress woocommerce wordpress-theming urlencode


    【解决方案1】:

    以下 sn-p 将为您解决问题!

    $decoded_url = urldecode('example.com/search/search+query%3Fpost_type%3Dproduct');
    
    echo $decoded_url;
    

    结果是:

    example.com/search/search query?post_type=product 
    

    【讨论】:

      【解决方案2】:

      urlencode_deep(混合$值)

      浏览数组、对象或标量,并对要在 URL 中使用的值进行编码。

      $value -(混合)(必需)要编码的数组或字符串。

      function urlencode_deep( $value ) {
          return map_deep( $value, 'urlencode' );
      }
      

      【讨论】:

        猜你喜欢
        • 2013-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-02
        • 1970-01-01
        • 2011-07-23
        • 2018-06-30
        • 2011-08-30
        相关资源
        最近更新 更多