gpt4 book ai didi

php - 在 PHP 中过滤类别(两个或多个)之间的共同值

转载 作者:行者123 更新时间:2023-11-29 20:21:34 25 4
gpt4 key购买 nike

我们使用 WordPress CMS 创建了各种类别。我们必须通过单击类别来过滤数据。当我单击两个以上类别时,我需要过滤类别值(数据)。我使用了 array_intersect 概念来选择类别之间的共同值。但它仅适用于两个类别。

当我单击(这是一个选择选项)两个以上类别时,它不起作用。请帮助我找到解决方案。

最佳答案

试试这个,它应该可以工作(但目前未经测试):

<?php

$args = array(
'post_type' => 'post',
'cat' => '33,45,56'
)

$query = new WP_Query( $args );

if( $query->have_posts() ) {

while( $query->have_posts() ): $query->the_post();
/* do stuff here */
endwhile;
wp_reset_postdata();

}

?>

检查WP Query Codex (Category Parameters)了解更多信息

关于php - 在 PHP 中过滤类别(两个或多个)之间的共同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39484636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com