0

I have an wordpress website, and in my new page I just see the news in principal language. If I change the language I can't see the posts. And the posts are translated with qtranslate plugin.

This is my code and how I get the posts:

<div class="infinite-scroll">
<?php
   $category = get_field('nome', get_the_ID());
   $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

   $custom_args = array(
                  'post_type' => 'post',
                  'posts_per_page' => 6,
                  'paged' => $paged,
                  'category_name' => $category,
                );

    $articles = new WP_Query( $custom_args );
    if ( $articles->have_posts() ) : while ( $articles->have_posts() ) : $articles->the_post(); // run the loop ?>
      <div class="col-xs-12 col-sm-6 col-md-4">
         <a class="news-link" href="<?php the_permalink() ?>">
          <div class="news">
            <div class="image">
              <?php the_post_thumbnail('thumbnail') ?>
               <div class="mask">
                <div class="icon">
                    <i class="icon-plus"></i>
                 </div>
              </div>

              </div>

             </div>
           </a>
          </div>
      <?php endwhile; ?>
      <?php
         if (function_exists(custom_pagination)) {
           custom_pagination($articles->max_num_pages,"",$paged);
         }
       ?>
       <?php else: ?>
       <article>
         <h1>Sorry...</h1>
         <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
        </article>
            <?php endif; ?>
        </div>

With principal language it list the posts well, If I change to another language it returns me the message error : Sorry, no posts matched your criteria.

What is the problem? Other content of website works well in several languages. This problem only happens with news.

Peter
  • 777
  • 2
  • 13
  • 34
user3242861
  • 1,839
  • 12
  • 48
  • 93

1 Answers1

-1

You're getting a category name from an ACF field, so if that's being translated then it might be the problem. Rather than getting the name, get the category's ID and use that instead (remember to change 'category_name' in $custom_args to just 'cat')

Peter HvD
  • 1,623
  • 1
  • 7
  • 14