使用按钮按子类别段塞过滤帖子



我加载了一个类别的子页面帖子,现在我尝试按他的子类别过滤这篇帖子,并获得链接到页面,比如mypage.com/subpage/?slug=点击按钮后的鱼,只看到鱼的帖子。

我应该使用$_GET吗?

有人能帮忙吗?

有我的代码谁加载我的所有文章从类别动物

<?php
$args = array(
'cat' => 50,
'posts_per_page' => '999',
'order' => 'ASC',
'orderby' => 'menu_order',
);
$the_query = new WP_Query($args);
// The Loop
if ($the_query->have_posts()) {
?>
<?php
while ($the_query->have_posts()) {
$the_query->the_post();
get_template_part( 'templates/content/content', 'animals' ); 
}
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
echo '';
}
?>

您可以这样使用:

if(isset($_GET['slug']))
{
$args = array(
'post_type' => 'post_type',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $_GET['slug']
)
)
);
}

最新更新