php - Wordpress - 使用 qtranslate 获取帖子
问题描述
我有一个 wordpress 网站,在我的新页面中,我只看到主要语言的新闻。如果我更改语言,我将看不到帖子。并且帖子是用qtranslate
插件翻译的。
这是我的代码以及我如何获得帖子:
<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>
使用主要语言,它可以很好地列出帖子,如果我更改为另一种语言,它会返回消息错误: Sorry, no posts matched your criteria.
问题是什么?网站的其他内容以多种语言运行良好。这个问题只发生在新闻上。
解决方案
您从 ACF 字段中获取类别名称,因此如果正在翻译,则可能是问题所在。与其获取名称,不如获取类别的 ID 并使用它(记得将'category_name'
$custom_args 更改为 just 'cat'
)
推荐阅读
- javascript - 如何制作多级上下文菜单?
- javascript - 我想通过ajax调用从地图中获取json数据
- python - Python Pandas:根据选定列的最重复值的降序限制1返回多列值
- python - 尝试使用标签时出现问题
- google-cloud-platform - 谷歌企业电子邮件别名,转发到多个帐户?
- spring - 无法从 spring.boot.autoconfigure.task 中自动装配 ThreadPoolTaskExecutor
- sql - 为什么错误传递给 LEFT 或 SUBSTRING 函数的长度参数无效?
- c# - 如何在水晶报表领域明智地订购行?
- r - 在R中将一列列表分成几列
- database - 如何从 WSO2 EI Studio 调用外部 Rest API?