<!-- wp:preformatted -->
<pre class="wp-block-preformatted">&lt;script&gt;
(function($){
    $(document).ready(function(e){
      var url = new URL(location.href);
      var params = new URLSearchParams(url.search);
      var yx = params.get('sort_by');
      var dest1 = null,dest2 = null;
      if ( yx != null ) {  
          //alert(yx);
          var tops = yx.split(',');
         if ( tops.length &gt; 1 ) {
           dest1 = tops[0];
           dest2 = tops[1];
         } else {
           dest1 = tops[0];
         }
      }

      var edest1 = edest2 = null;
      $('ul.grid--view-items li').each(function(e){
        var link_url = $(this).find('a.grid-view-item__link').attr('href');
        if ( dest1 != null &amp;&amp; link_url.indexOf(dest1) != -1 ) {
          edest1 = $(this);
        } else if ( dest2 != null &amp;&amp; link_url.indexOf(dest2) != -1 ) {
          edest2 = $(this);
        }
      });  

      if ( edest2 != null ) {
        $('ul.grid--view-items').prepend(edest2);
      }
      if ( edest1 != null ) {
        $('ul.grid--view-items').prepend(edest1);
      }

      edest2 = null;

      if ( dest2 != null &amp;&amp; edest2 == null  ) {
        var durl = window.location.href.toString();
        var durl_array = durl.split('?');
        var rurl = durl_array[0] + '/products/' + dest2 + '.json';
        alert(rurl);
        $.ajax(
          {
            url:rurl,
            success: function(e){
              alert(JSON.stringify(e));

          //$('ul.grid--view-items').prepend(onep);
            }
          }
        );
      }


});
})(jQuery);

  &lt;/script&gt;</pre>
<!-- /wp:preformatted -->