WPML : Get The Posts Of Current Language

Recently I’m working on of client project where I  used WPML plugin to make the site multilingual.  One of the problem I’m facing with this, when I fetch the posts by using the <?php get_posts( $args ) ?> . It always returns the posts of all language. Where I want only the posts of the current language.

After digging deeper I finally found the reason. There is one argument of called “suppress_filters” which is true by default and it disabled all extra filters in the query. If you set is as false, the query will only get the posts of the current language.


$args = array(
  'posts_per_page'   => 5,
  'post_type'        => 'post',
  'post_status'      => 'publish',
  'orderby'          => 'rand',
  'suppress_filters' => false 

$posts_array = get_posts( $args );



Be First to Comment

    Leave a Reply

    Your email address will not be published.