gpt4 book ai didi

php - 根据条件参数过滤 WordPress 中的帖子

转载 作者:行者123 更新时间:2023-11-29 15:43:16 25 4
gpt4 key购买 nike

整个前端以及将选定的类别从菜单传递到后端正在运行。

使用参数(类别 ID)作为过滤器不起作用。

显示的表中的每个项目都是一个类别。结果是帖子。

// cats brand |  cats type     |  cats can not be
//----------------------------------------
// 1 dell | 15 pc | 40 broken
// 2 ibm | 16 smartphone | 41 used
// 3 samsung | 17 monitor | 42 remanufactured
// 4 hp | 18 printer

我需要返回的是这个示例的工作原理:

-> 来自戴尔或惠普类别的帖子

-> 也属于 PC 或显示器类别

-> 不属于损坏的类别

$args = array(                   
'category_name' => 'dell,hp',
'category__in' => '15,17',
'category__not_in' => '40'
);
$query = new WP_Query( $args );
?>

<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
echo "--------------------<br>";
echo "<br>" . the_title();
echo "<br>" . the_category();
endwhile;
else:
?>
<p>no results found.</p>
<?php
endif;
wp_reset_postdata();
?>

最佳答案

试试这个代码,

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$cat = ( isset( $_GET['category_select'] ) ) ? $_GET['category_select'] : 1;
$args = array (
'cat' => $cat,
'posts_per_page' => 10,
'paged' => $paged
);
$query = new WP_Query( $args );

if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
echo "--------------------<br>";
echo "<br>" . the_title();
echo "<br>" . the_category();
endwhile;
else:
?>
<p>no results found.</p>
<?php
endif;
wp_reset_postdata();?>

关于php - 根据条件参数过滤 WordPress 中的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57351320/

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