Search Unleashed
Displaying results by language (3 posts)

  1. joaomorgado
    Posted 6 years ago #


    I am using WordPress 3.0 with Silverio Theme and WPML tranlations.
    Since i am using a lot of Custom fields, i decided to take advantage of Search Unleashed but now i cant show search results by language.

    if i search on english page, it delivers all the results ignoring lang=en!

    Do you know how can i filter the search results by language?

    Thanks a lot

  2. joaomorgado
    Posted 6 years ago #

    Any idea?
    My search results are showing all the posts: english and spanish. So i have duplicated entries...

    Is it possible to filter the language results by language?

  3. Renuplex
    Posted 5 years ago #

    Hi Joaomorgado,

    I had a similar issue but using langswitch and I coded an easy workaround for the MYSQL fulltext search engine.

    Here are the things I added and their role:

    1. In search-unleashed/engines/mysql.php:
    In install_engine(), replace:
    $post = "CREATE TABLE'{$wpdb->prefix}search_post'('post_id'int(11) unsigned NOT NULL,";
    $post = "CREATE TABLE'{$wpdb->prefix}search_post'('post_id'int(11) unsigned NOT NULL, post_lang CHAR(2) DEFAULT NULL,";

    This will create a new column in the wp_search_post table in the database that can hold the language and can then be used to retrieve only posts in a given language.

    2. In search-unleashed/models/spider.php
    In gather_for_post, just before returning $fields, you need to add code to add the correct language for each post in the database. This is unfortunately dependent on your ML plugin so you will have to figure out how to get a post language code (ex:en,es) from WPML. It should be quite easy.
    For my plugin (langswitch + a custom plugin I called langnav), it looks like this:
    $post_lang = langnav_get_post_lang($post_entry);

    Then, you have to insert the language in the fields so it will be inserted in the DB along with the post.
    The full code looks like this:

    if (function_exists('langnav_get_post_lang')){
                        $post_lang = langnav_get_post_lang($post_entry);
                            $fields['post_lang'] = array( 'data' => $post_lang, 'priority' => 1);

    3. In search-unleashed/engines/mysql.php
    In posts_request(), change the line:
    $sql .= " WHERE 1=1 ";


    if (function_exists('langswitch_current_lang')){
    $sql .= " WHERE WP_SEARCH_POST.post_lang='".langswitch_current_lang()."'";
    $sql .= " WHERE 1=1 ";

    Note again that here langswitch_current_lang() returns the language we want the posts in. If you want to use something like lang=en, then it would look like this:

    if ($_GET['lang']){
    $sql .= " WHERE WP_SEARCH_POST.post_lang='".$_GET['lang']."'";
    $sql .= " WHERE 1=1 ";

    OR like this:

    if ($wp_query->get('lang')){
    $sql .= " WHERE WP_SEARCH_POST.post_lang='".$wp_query->get('lang')."'";
    $sql .= " WHERE 1=1 ";

    That's it!
    I know it's a bit problematic that it's not a generic solution that works with any ML plugin but I think it should help you get on the right tracks.
    Note that on my setup it works perfectly!


Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic