2

I'm using polylang on my wordpress page. I want to translate the pages, but keep the blog in only one language. I've used this hook:


function turn_blogposts_translation_off( $post_types, $is_settings ) {
  unset( $post_types['post'] );

  return $post_types;
}

add_filter( 'pll_get_post_types', 'turn_blogposts_translation_off', 10, 2 );

which does disable translations for posts, but if I am viewing my page in the second language, no blog posts are shown, since there are none in that language.

How can I show English posts (main language) while viewing the site in other languages?

Filip
  • 855
  • 2
  • 18
  • 38
  • I would also like to know how to do this. – Phlame May 01 '20 at 05:55
  • 2
    I think you can do it like that, it's already explained in this doc page; https://polylang.wordpress.com/documentation/documentation-for-developers/general/ `$posts = get_posts(array( 'post_type' => 'post', 'lang' => 'fr', // use language slug in the query 'showposts' => 5 ));` – ewroman Jul 20 '20 at 16:19

1 Answers1

0

Thanks for @ewroman's comment. The document already has an answer for that

Is it possible to query all languages?

Yes it is. Example:

$posts = get_posts(array(
   'post_type' => 'post',
   'lang' => '', // query posts in all languages
   'showposts' => 5
));

This lang filter can also apply to the WP_Query because their parameters are the same.

$query_args = array(
    'post_type' => 'post',
    'lang'      => '', // query posts in all languages
);
$query = new WP_Query($query_args);
Tyson Z
  • 338
  • 1
  • 5