I am using Polylang plugin, which assigns each post to a taxonomy 'language'.
While using get_adjacent_post()
I want to bring only those posts that belong to the language currently displayed.
So I am writing the following:
$prev_post = get_adjacent_post( true, '', true, 'language' );
$next_post = get_adjacent_post( true, '', false, 'language' );
But this brings the next and previous posts independently from the language they are currently in. Why?
I understand in the documentation $in_same_term
(first value) specifies whether post should be in a same taxonomy term. And that $taxonomy
is the taxonomy name, if $in_same_term is true. However this is not working in my case, I am getting all languages in previous / next link.
Why I am using adjacent_posts() and not get_next_post() or get_previous_post()?
Because it's mandatory in this case that I am able to sort these next / previous posts by menu_order, something that get_next_post(), get_previous_post() can't do. So I am implementing a filter in functions.php to achieve this.
If it's relevant to this case, in that filter I am specifying this: https://gist.github.com/yoren/81d1ca3a8448256bf65c