Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

Ivan Antipov on "Polylang - switching language on the fly and duplicate URL's"

$
0
0

OK that didn't quite work - however this did, at the top of single.php:

global $wp_query, $polylang;

if($wp_query->post_count > 1) {
	foreach($wp_query->posts as $k=>$found_post) {
		if($polylang->get_post_language($found_post->ID)->slug == pll_current_language()) {
			$wp_query->post = $wp_query->posts[$k];
			$wp_query->queried_object = $wp_query->posts[$k];
			$wp_query->queried_object_id = $wp_query->posts[$k]->ID;

			if(!$wp_query->posts[0]) {
				$wp_query->posts[0] = $wp_query->posts[$k];
				unset($wp_query->posts[$k]);
			}
		} else {
			unset($wp_query->posts[$k]);
		}
	}

	$wp_query->post_count = count($wp_query->posts);
	$wp_query->found_posts = count($wp_query->posts);
}

No need to check the post lang in the while loop.


Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>