php - 是否可以在 Wordpress 中将术语数组与 array_intersect() 匹配?
问题描述
或者我必须使用 get_post() 这样的东西来达到目的:
$args= array(
'post_type' => 'post',
'posts_per_page' => '1',
'orderby' => 'rand',
'tax_query' => array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category-1',
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category-2',
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category-3',
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category-4',
),
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category-5',
),
)
);
目标是匹配下一个/上一个帖子的整个术语数组,因为 get_next_post 具有 OR 条件,而不是 AND。
使用我当前按钮使用的 in_same_term 设置为 true 的本机 WP get_next_post 机制,如果当前帖子具有术语 A、B 和 C,它将获取仅具有 A 和 C、或仅 A、或仅 A 和 B 的下一个帖子,它甚至会获取包含 A、B、C 和 D 的帖子。相比之下,我需要的是:
如果当前帖子有术语 A、B 和 C,则下一个/上一个帖子也必须包含所有术语 A、B 和 C,并且不应允许像 D 这样的额外内容,意思是:相同的术语数组。
因此,不应允许仅 A 和 C,或仅 A,或仅 A 和 B,或 ABCD。
解决方案
推荐阅读
- can-bus - 如何使用 CAPL 程序发送消息
- python - 如何在不分隔字符的情况下打印枚举列表(带有字符)
- c# - ASP.NET:将消息从控制器传递到视图(ViewBag、ViewData 或 TempData)
- php - 如何将动态变量从 PHP 语法转换为 twig
- typescript - Typescript - Morgan 和 logger.stream 导致 lint 错误
- java - Android搜索过滤器在没有结果时显示文本视图
- .net-core-2.1 - 如何将本机二进制文件打包为全局 dotnet 工具
- javascript - 幻灯片容器相同高度
- c# - 如何不显示部署在 hololens 中的 UWP 应用程序的 UI?
- python - 失败:ImportError(没有名为“bunch”的模块)