我有一个自定义的帖子类型“学者”,它有一个档案。我想按一个名为“year”的自定义元字段进行排序,我正在使用pre_get_posts
:
add_action(\'pre_get_posts\', \'my_queries\');
function my_queries($query)
{
if (!$query->is_main_query()) return;
if ($query->query[\'post_type\'] == \'scholars\') {
$query->set(\'posts_per_page\', -1);
$query->set(\'meta_key\', \'year\');
$query->set(\'orderby\', \'meta_value\');
}
}
这在归档页面(主列表)中运行良好,但next_post_link
和previous_post_link
在单个帖子中不同步。它们仍然按日期排序,而不是按自定义的“年份”。我在单个页面上有一个自定义查询,使用WP_Query
显示相关帖子,但我尝试删除它,但仍然不起作用。
这是存档页面:
<div class="large-12 columns">
<?php
if (have_posts()) {
while (have_posts()) {
the_post();
// this just loads an <article>
get_template_part(\'content\', \'scholars\');
}
} else {
echo \'<h2>Nothing found.</h2>\';
}
?>
</div>
这是一页:<?php the_post() ?>
<div class="large-12 columns">
<nav class="scholars-navigation">
<span class="prev"><?php previous_post_link() ?></span>
<h2><?php the_title() ?></h2>
<span class="next"><?php next_post_link() ?></span>
</nav>
</div>
<div class="large-3 columns scholar-info">
<img src="<?php the_field(\'photo\') ?>" alt="" />
<h3><?php the_field(\'year\') ?> Scholar</h3>
</div>
你知道为什么它不起作用吗?Edit: 在查看了其他相关答案后,发现这似乎是不可能的,因为内置功能是现成的this plugin 但我愿意接受任何解决方案。
Edit: Pfff,它甚至不能使用该插件,不知道问题是什么:
next_post_link_plus(\'meta_key=year&order_by=numeric\')