[Plugin Zd Multilang] WordPress Search won′t work
-
Hello,
I′m developing a theme with search and I can′t make the wordpress search work with the ZdMultilang translated fields, it only searchs the original post.
I switch languages in the backend of ZdMultilang and I was able to search in the translated language, (it became the main language), but the now translated language returned no results.
I research a lot in the web and found a function in wordpress codex to append a plugin table to the wpdb post search. It′s down bellow here:
add_filter('posts_join', 'mlang_search_join' ); add_filter('posts_where', 'mlang_search_where' ); add_filter('posts_groupby', 'mlang_search_groupby' ); function mlang_search_join($join) { global $zd_ml_trans, $wpdb; if(is_search()) { $join .= " LEFT JOIN $zd_ml_trans ON " . $wpdb->posts . ".ID = " . $zd_ml_trans . ".post_content "; } return $join; } function multilang_search_where($where) { if( is_search() ) { $where = preg_replace( "/\(\s*post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", "(post_title LIKE \\1) OR (post_content LIKE \\1) OR (post_excerpt LIKE \\1) OR (post_status LIKE \\1)", $where ); } return $where; } function multilang_search_groupby( $groupby ) { global $wpdb; if( !is_search() ) { return $groupby; } // we need to group on post ID $mygroupby = "{$wpdb->posts}.ID"; if( preg_match( "/$mygroupby/", $groupby )) { // grouping we need is already there return $groupby; } if( !strlen(trim($groupby))) { // groupby was empty, use ours return $mygroupby; } // wasn't empty, append ours return $groupby . ", " . $mygroupby; }
I don′t know why this is not working, but I would really appreciate any help on this matter. With the Search Everything sometimes it returns a result sometimes don′t.
Also, I noticed when you perform a search, you can′t switch languages. It would be nice to have a function to add that change to the plugin.
Tiago Morena
- The topic ‘[Plugin Zd Multilang] WordPress Search won′t work’ is closed to new replies.