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.