WordPress: wp-autosuggest search and qTranslate plugins working together
20. Apr 10 | Web | No Comments »Here is a little tutorial for those who want to use qTranslate and wp-autosuggest on the same WordPress website and make them work hand in hand. But first a little intro for those who are not familiar with the mentioned plugins.
qTranslate is a great plugin if you need a web page in several languages. I have implemented quite a few web sites with it and it works perfectly. It usually needs some adjustments in the templates but it is versatile.
In my opinion the best autosuggest plugin for WordPress is wp-autosuggest. This plugin enables you to display search results while you type the search query in the WordPress search box.
For qTranslate you will have to adapt search box action and button in your WordPress template file searchform.php (here is an example for English and Slovenian language):
<?php if (qtrans_getLanguage()=="en"): ?>
<div class="white_box_search">
<form method="get" id="searchForm" action="
<?php echo
qtrans_convertURL('http://www.domainname.si/en/', 'en'); ?>">
<input type="text" value="" name="s" id="s" alt="Search"/>
<input id="searchsubmit" value="" type="submit" />
</form>
</div>
<?php endif; ?>
<?php if (qtrans_getLanguage()=="si"): ?>
<div class="white_box_search">
<form method="get" id="searchForm" action="
<?php
echo qtrans_convertURL('http://www.domainname.si/si/', 'si'); ?>">
<input type="text" value="" name="s" id="s" alt="Iskanje"/>
<input id="searchsubmit" value="" type="submit" />
</form>
</div>
<?php endif; ?>
With wp-autosuggest plugin your main problem will be how to display search results in the right language. The key is in editing autosuggest.php. Find the variable autosuggest_options and edit script.
script: "<?php echo AUTOSUGGEST_DIR; ?> /autosuggest.php?wpas_action=query& <?php if (qtrans_getLanguage()=="sl"): ?> lang=sl <?php endif; ?>&",
Insert as many languages as you need at the end of the URL and don’t forget the “&“ at the end.
And the final product:


Autosuggest displays the English version of the article on English version of the web site and Slovenian on Slovene. I’ll post the link to the web site when it comes live.
Other links:



Be the first to post a comment!