How to get the forum search to sort by 'Relevance' by default

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigbear83
    New Member
    • Nov 2015
    • 11
    • 5.1.x

    How to get the forum search to sort by 'Relevance' by default

    This must be a very simple edit somewhere but for the life of me I've spent hours trying to figure this w/o any results. Could someone kindly point me in the right direction?

    Basically this is what I'm looking for-

    When a user makes a search on the forums from the main page (not the advanced search page)



    The search results always defaults to sort by "Date - last update"



    I really need this to sort by "Relevance" by default ... is there any way to do this at all? What am I missing here?

    I suspect this must be a very simple edit somewhere that I am totally missing here but I'm not entirely sure what it is...

    I'm running the latest vB 5.2.1

    Any help I can get regarding my issue here would be greatly appreciated! Many thx in advance
  • Mark.B
    vBulletin Support
    • Feb 2004
    • 24288
    • 6.0.X

    #2
    This would require code customisations to achieve, there is no way to do this in the default software.

    It would be worth asking at www.vbulletin.org, the modification and customisation site.
    MARK.B
    vBulletin Support
    ------------
    My Unofficial vBulletin 6.0.0 Demo: https://www.talknewsuk.com
    My Unofficial vBulletin Cloud Demo: https://www.adminammo.com

    Comment

    • glennrocksvb
      Former vBulletin Developer
      • Mar 2011
      • 4021
      • 5.7.X

      #3
      You can do this via template hook. Create a template hook at footer_before_body_end hook location with the following template code.

      Code:
      <script>
      (function($) {
          $(window).on('load', function() {
              $('#searchForm').on('submit.searchform', function() {
                  var $searchJson = $('#header input[name="searchJSON"]'),
                      decodedJson = decodeURIComponent($searchJson.val()),
                      parsedJson;
      
                  try {
                      parsedJson = $.parseJSON(decodedJson);
                      parsedJson.sort = 'relevance';
                      $searchJson.val(JSON.stringify(parsedJson));
                  }
                  catch(e){}
                  
              });
          });
      })(jQuery);
      </script>
      If you don't know how to create a template hook, follow one of my mods in my signature below. The instructions should be similar.

      Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

      Comment

      • bigbear83
        New Member
        • Nov 2015
        • 11
        • 5.1.x

        #4
        Glenn Vergara sweet! Thx a ton for that ... works a treat!

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...