我想要一个自定义页面,在那里我可以根据Url参数(猫和标签)获得所有帖子
<a href="localhost/celeb_page.php?cat=38&tag=aamir-khan" >View All Photo of Aamir</a>
注:cat=38
是我的类别,即Photo gallery
,tag = aamir-khan
是taxonomy slug
因此,如果点击上面的链接,那么与aamir khan
相关的照片库帖子将根据其猫id和标签显示
请注意,它不是任何自定义的post,也不是自定义的分类法。
在wrodpress 中有点让我困惑
我认为以下代码将帮助您从类别和标签中获取帖子。你可以从url中获取类别和标签。
$category=$_GET["category"];
$tag=$_GET["tag"];
global $wp_query;
$args = array(
'category__and' => $category,
'tag__in' => $tag, //must use tag id for this field
'posts_per_page' => -1); //get all posts
$posts = get_posts($args);
foreach ($posts as $post) :
//do stuff
endforeach;