wp_get_recent_posts polylang
-
I have a footer that displays 2 lists of recent post: one with the 2 most recent posts in the category ‘news’ and one that displays the 2 most recent blogposts (all categories except ‘news’).
To do this, I use wp_get_recent_posts. Following is the code that displays the 2 most recent posts from the category ‘news’. This works polylang. So, when the lang is EN, it will display the 2 most recent EN posts in the EN category ‘news’. When the lang is FR, it will display the 2 most recent FR posts in the FR category ‘news’.
<?php global $post; $recent_news_posts = wp_get_recent_posts( array( 'numberposts' => 2, 'category' => 24 /* EN news category */ ) ); foreach( $recent_news_posts as $recent ){ $post = (object) $recent; echo '<a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a>'; } wp_reset_postdata(); ?>
For the second list (all post except category ‘news’) I use the same code but instead of ‘category’ => 24, I put ‘category__not_in’ => 24.
This doesn’t work at all. It display the most recent posts in any category AND in any language. It seems to query from a pool of all the posts in all the languages.
So, not only does the exclude category not work, it also ‘breaks’ polylang. Any ideas how to solve this?
- The topic ‘wp_get_recent_posts polylang’ is closed to new replies.