Php 使用按钮按子类别slug筛选post
我用一个类别加载子页面帖子,现在我尝试按他的子类别筛选帖子,并在单击按钮后获得指向某些页面的链接,如mypage.com/subpage/?slug=fish,然后只查看fish帖子 我应该使用$你得到了吗 有人能帮忙吗 这是我的代码谁加载我的所有文章从类别动物Php 使用按钮按子类别slug筛选post,php,html,jquery,wordpress,filter,Php,Html,Jquery,Wordpress,Filter,我用一个类别加载子页面帖子,现在我尝试按他的子类别筛选帖子,并在单击按钮后获得指向某些页面的链接,如mypage.com/subpage/?slug=fish,然后只查看fish帖子 我应该使用$你得到了吗 有人能帮忙吗 这是我的代码谁加载我的所有文章从类别动物 <?php $args = array( 'cat' => 50, 'posts_per_page' => '999', '
<?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']
)
)
);
}