我知道有很多关于如何按类别过滤标签的问题,但我需要一些帮助。
$args = array(
'tag' => get_queried_object()->slug,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'interior',
),
)
);
//get all posts
$posts_new = get_posts($args);
它可以工作,但我想从 URL 中获取类似于example.com/tag/lexington/?category=interior
或的类别,以便在上述查询example.com/tag/lexington/category/interior
的参数中使用它。terms
感谢您的关注。
在过去的几个小时里,我试图在我的functions.php
:
function category_tag_rewrite_rule()
{
add_rewrite_tag('%tag_category%', '([^&]+)');
add_rewrite_rule('^tag/([^/]+)/?', 'index.php?tag=$matches[1]&tag_category=$matches[2]');
}
add_action('init', 'category_tag_rewrite_rule');
现在它把我发送到标签页(tag.php
模板),但get_query_var('tag_category')
没有从这个模板返回给我。
我的正则表达式可能有问题。