We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    The problem is this: for friendly URLs, MODX's .htaccess file defaults to something like this:

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    


    Where it uses "q" as its query string. In other words, http://yoursite.com/some/page.html is translated by the .htaccess file to be equivalent to http://yoursite.com/index.php?q=some/page.html

    Whereas a Google widget typically gets installed via form something like this (and a corresponding bit of javascript on the search-results page):

    <form method="get" action="[[~123]]">
      <input type="hidden" name="cx" value="0123456789" />
      <input type="hidden" name="ie" value="UTF-8" />
      <input type="text" name="q" class="menu-search"/>
      <input type="submit" value="" />
    </form>


    The problem is that both MODX's .htaccess file and Google's search form try to utilize the q parameter. Usually, MODX wins because the .htaccess file writes to the q parameter before anything else. So your search results constantly come back empty.

    Solution 1

    There are 2 possible solutions here. First, we can update our Javascript to include one a gcse markup that specifies the "queryParameterName" value to be something other than the "q" parameter:

    <script>
    	(function() {
    		var cx = '0123456789';
    		var gcse = document.createElement('script');
    		gcse.TYPE = 'text/javascript';
    		gcse.async = true;
    		gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
    			'//www.google.com/cse/cse.js?cx=' + cx;
    		var s = document.getElementsByTagName('script')[0];
    		s.parentNode.insertBefore(gcse, s);
    	  })();
    </script>
    <gcse:searchresults-only linkTarget="_self" queryParameterName="search"></gcse:searchresults-only>
    


    Here the query parameter has been set to be "search", so your search form should be update to reflect this:

    <input type="text" name="search" class="menu-search"/>


    See https://developers.google.com/custom-search/docs/js/cselement-reference#csedrawoptions-el for more info.

    Solution 2

    The other option is to update your MODX System Settings so MODX uses some other query parameter. Update the request_param_alias to be something other than "q", e.g. "query", then update your .htaccess file to use the new paramter, e.g.

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?query=$1 [L,QSA]
    


    Hope that helps someone.
      • 3749
      • 24,544 Posts
      Or change the MODX request_param_alias System Setting from 'q' to something else. wink
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 11055 ☆ A M B ☆
        • 3,112 Posts
        then we should have this "[mod]query" as default.
          Rico
          Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
          MODx is great, but knowing how to use it well makes it perfect!

          www.virtudraft.com

          Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

          Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

          Maintainter/contributor of Babel

          Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
          • 2762
          • 1,198 Posts
          if I understand, it's the same problem that I had with modx Evolution and google adsense search, some years ago.
          Solved with a simple trick :
          In your google search code, replace "q" with "Q".
            Free MODx Graphic resources and Templates www.tattoocms.it
            -----------------------------------------------------

            MODx IT  www.modx.it
            -----------------------------------------------------

            bubuna.com - Web & Multimedia Design