Title: [Plugin: Polylang] (fix for) adjacent post function not working with v.0.6
Last modified: August 20, 2016

---

# [Plugin: Polylang] (fix for) adjacent post function not working with v.0.6

 *  Resolved [serban](https://wordpress.org/support/users/serban/)
 * (@serban)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-polylang-get-adjacent-post-function-not-working-with-v06/)
 * I have installed WP 3.3.1 with a child theme of Twentyeleven, Theme Extensions
   plugin (for Twentyeleven theme) and Polylang v.0.6 .
    While having just 2 posts
   for each language, I found an error log on the server (shared hosting) showing
   a MySQL error:
 * `WordPress database error You have an error in your SQL syntax; check the manual
   that corresponds to your MySQL server version for the right syntax to use near'
   ON object_id = ID WHERE post_type = 'post' AND post_status = 'publish' AND term_'
   at line 1 for query SELECT YEAR(post_date) AS`year`, MONTH(post_date) AS`month`,
   count(ID) as posts FROM wp_posts INNER JOIN ON object_id = ID WHERE post_type
   = 'post' AND post_status = 'publish' AND term_taxonomy_id = 3 GROUP BY YEAR(post_date),
   MONTH(post_date) ORDER BY post_date DESC made by require, require_once, include,
   get_sidebar, locate_template, load_template, require_once, dynamic_sidebar, call_user_func_array,
   WP_Widget->display_callback, WP_Widget_Archives->widget, wp_get_archives`
 * So, I have searching into the code and I found a missing globalize of the class
   $wpdb around the line 432, file core.php (/polylang/include/core.php).
    To fix
   the problem I have added a line `global $wpdb;` just before this line `return
   $sql . $GLOBALS['wpdb']->prepare(" INNER JOIN $wpdb->term_relationships ON object_id
   = ID");` so the complete code of this function is now:
 *     ```
       // modifies the sql request for wp_get_archives an get_adjacent_post to filter by the current language
       	function posts_join($sql) {
                       global $wpdb;
       		return $sql .  $GLOBALS['wpdb']->prepare(" INNER JOIN $wpdb->term_relationships ON object_id = ID");
       	}
       ```
   
 * Maybe it helps…
 * [http://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-polylang-get-adjacent-post-function-not-working-with-v06/#post-2502773)
 * Thank you very much !
 * I was already aware of this as this is the solution for a bug ([archives widget not working](http://wordpress.org/support/topic/plugin-polylang-archives-widget-not-working-anymore?replies=11#post-2546495))
   reported some days ago. But don’t misinterpret my words, this kind of help is
   very much appreciated 🙂
 * The correction will be included in v0.6.1 coming soon…

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Polylang] (fix for) adjacent post function not working with 
v.0.6’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

## Tags

 * [get_adjacent_post](https://wordpress.org/support/topic-tag/get_adjacent_post/)
 * [sql-error](https://wordpress.org/support/topic-tag/sql-error/)

 * 1 reply
 * 2 participants
 * Last reply from: [Chouby](https://wordpress.org/support/users/chouby/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-polylang-get-adjacent-post-function-not-working-with-v06/#post-2502773)
 * Status: resolved