• hey, i want to know can i hide the string ?

    “?s=&ymm_search=1&orderby=name&post_type=product&_make”

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    Try to add the line:

    
    add_action( 'init', array($this, 'addUrlParameters'));
    

    after the line:

    
    add_filter('get_search_query', array($this, 'shop_order_search_label' ));
    

    and add the code:

    
    public function addUrlParameters(){ 
         if (isset($_GET['_make']) && !isset($_GET['s']) && !isset($_GET['ymm_search']) && !isset($_GET['post_type']) && !is_product_category()){
           $_GET['s'] = '';
           $_GET['ymm_search'] = 1;
           $_GET['post_type'] = 'product';
           $_GET['orderby'] = 'name';       
         }
      }
    

    before the line:

    
      public function applyFilter(){
    

    in the line:
    wp-content/plugins/ymm-search/Controller/Product.php

    Replace the line:

    
    var params = (this.isCategoryPage && this.filterCategoryPage) || categoryUrl ? {} : {s:searchWord, ymm_search:1, post_type:'product'};
    

    with:

    
     var params = (this.isCategoryPage && this.filterCategoryPage) || categoryUrl ? {} : {}; // add search parameters with php script {s:searchWord, ymm_search:1, post_type:'product'}
    

    in the file:
    wp-content/plugins/ymm-search/view/frontend/web/main.js

    Then refresh your browser cache. And try to access the search results page only with make, model and year parameters:
    yourwebsite.com/?_make=HONDA%20%2F%20本田&_model=CIVIC%20喜美&_trim=8代%201.8%20(K12)&_engine=2006-

    Stanislav

    Thread Starter power1parts

    (@power1parts)

    Thanks for your help. But it isnt work. It also crash my site. I’ll send my ymm file to your email.

    Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    For anyone else who need SEO URLs on the search results page of this plugin.

    Add the code:

    
    add_action('init', '_ymm_add_url_parameters');
    add_filter('query_vars', '_ymm_add_query_vars');
    add_action('parse_query', '_ymm_parse_query');
    
    function _ymm_add_url_parameters(){ 
       // To make it work with SEO URL like:
       // https://website.com/vehicle/BMW/X3/2008/
       // instead of:
       // https://website.com/?s=&ymm_search=1&post_type=product&_make=BMW&_model=X3&_year=2008
       // 
       // Don't forget to refresh the wordpress permalink settings after changing the rewrite rules in:
       // WordPress dashboard -> Settings -> Permalink 
       //   click the "Save changes" button at the bottom of the page
       add_rewrite_rule('^vehicle/([A-Za-z0-9-]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]', 'top');
       add_rewrite_rule('^vehicle/([A-Za-z0-9-]+)/page/([0-9]{1,})/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&paged=$matches[2]', 'top');   
       add_rewrite_rule('^vehicle/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]', 'top');
       add_rewrite_rule('^vehicle/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/page/([0-9]{1,})/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]&paged=$matches[3]', 'top');
       add_rewrite_rule('^vehicle/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]&_year=$matches[3]', 'top');
       add_rewrite_rule('^vehicle/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/page/([0-9]{1,})/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]&_year=$matches[3]&paged=$matches[4]', 'top');   
    }
    
    function _ymm_add_query_vars($aVars) {
      $aVars[] = "ymm_search";
      $aVars[] = "_make";
      $aVars[] = "_model";
      $aVars[] = "_year";                 
      return $aVars;
    }
    
    function _ymm_parse_query($where) {  
      $ymm_make = get_query_var('_make');
      if ($ymm_make){
       $_GET['ymm_search'] = get_query_var('ymm_search');
       $_GET['_make'] = get_query_var('_make');
       $_GET['_model'] = get_query_var('_model');
       $_GET['_year'] = get_query_var('_year');
       $_GET['s'] = get_query_var('s');	 		 	 		 		 
      }    
    }
    

    to the end of the file:
    wp-content/plugins/ymm-search/ymm-search.php

    Replace the code:

    
    window.location.href = url + '?' + $.param(params);
    

    with

    
    if (!categoryUrl){        
      var pNames = this.levelParameterNames;
      var l = pNames.length;
      url = url.replace(/\/+$/, '');
      url += '/vehicle/';
      for (var i=0;i<l;i++) {
        if (values[pNames[i]] != undefined){
          url += values[pNames[i]] + '/';  
        } 
      }
      window.location.href = url;    
    } else {           
      window.location.href = url + '?' + $.param(params);
    }
    

    in the file:
    wp-content/plugins/ymm-search/view/frontend/web/main.js

    Then refresh the wordpress permalink settings in:
    Wordpress dashboard -> Settings -> Permalink
    Click the “Save changes” button at the bottom of the page without any changes.

    Then refresh be browser cache and try to access the search results page as:
    https://yourwebsite.com/vehicle/BMW/X3/2008/
    instead of:
    https://yourwebsite.com/?s=&ymm_search=1&post_type=product&_make=BMW&_model=X3&_year=2008

    Stanislav

    Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    If someone need to use Chinese Letters in the URL it is possible to use a regular expression like this:

    
    add_rewrite_rule('^vehicle/([^/]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]', 'top');
    

    and then url decode it:

    
    $_GET['_make'] = urldecode(get_query_var('_make'));
    

    I have found this workaround on the page:
    https://wp-hackers.automattic.narkive.com/OSreoAIN/unicode-url-rewriting-using-add-rewrite-rule

    Stanislav

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is it possible to hide ymm Query Strings’ is closed to new replies.