0
votes

I have such a problem. On my WordPress site, I use WPML. I have several categories of posts. For each category I have a page template, this is not category.php. In order to display all posts on the page with pagination I use WP_Query. It looks like this.

...
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
  'cat' => 41,
  'posts_per_page' => 10,
  'paged' => $paged
));
?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php get_template_part('template-parts/content', 'record', get_post_format()); ?>
<?php endwhile; ?>
<?php
echo paginate_links( array(
  'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
  'total' => $query->max_num_pages,
  'current' => max( 1, get_query_var( 'paged' ) ),
  'format' => '?paged=%#%',
  'show_all' => false,
  'type' => 'plain',
  'end_size' => 1,
  'mid_size' => 2,
  'prev_next' => true,
  'prev_text' => '<svg class=\'pagination__previous\'><use xlink:href=' . get_template_directory_uri() . '/img/svg/sprite.svg#menu__arrow' . ' ></use></svg>',
  'next_text' => '<svg class=\'pagination__next\'><use xlink:href=' . get_template_directory_uri() . '/img/svg/sprite.svg#menu__arrow' . ' ></use></svg>',
  'add_args' => false,
  'add_fragment' => '',
));
?>
<?php wp_reset_postdata(); ?>
...

So cat=41 is ID of a category. And on default RU language the posts are displayed as it is expected. But when I switch to other languages EN or UK (in my situation) the page with posts is empty. Can you advise me how to fix it?

2

2 Answers

0
votes

Try Suppress Filter not tested it but it will help.

$query = new WP_Query( array(
   'cat' => 41,
   'posts_per_page' => 10,
   'paged' => $paged
   'suppress_filters' => false,
));
0
votes

I have found a solution. But it looks strange. No need in suppress_filters. When I select cat 41 only default language is selected other languages are not displayed. BUT if I will select 44 (the same category but in non-default language). I mean that category "News" in default Russian has ID 41 (slug: news-ru) and this category in English has ID 44 (slug: news-en). So, if I select 44 everything works fine. When I am in Default the post in default are displayed. When I switch to English the posts are displayed in English and more )) when I switch to Ukrainian (slug: news-uk, ID: 49) the third language all posts are displayed in Ukrainian. Magic? Has anyone explanation?