WordPress - 按标签显示自定义帖子类型 (PHP)
我在让我的帖子在 Wordpress 中通过标签名称显示时遇到问题。我有一个名为“评论”的自定义帖子类型,其中有一个名为“游戏类型”的(分类?)类别。在游戏类型中,我有一个名为“最新”的标签。
我正在尝试显示由“最新”标签标记的帖子。我尝试过以下代码,但它不起作用,我不确定为什么:
$args = array( 'tax_query' => array( array( 'taxonomy' => 'Gametypes', 'field' => 'slug', 'terms' => 'newest' ) ) );
$postslist = get_posts( $args );
我尝试过使用或不使用大写开头字母的不同迭代,但我似乎无法让它工作。谁能阐明我做错了什么?我可以使用以下代码从评论中提取每个帖子(带标签和不带标签的帖子):
$args = array( 'post_type' => 'Reviews', 'numberposts' => 6, 'order'=> 'DESC', 'orderby' => 'date' );
如果此信息有帮助。我希望有人能引导我走向正确的方向!
I am having issues getting my posts to be shown by the tag-name in Wordpress. I have a Custom Post Type called Reviews with a (taxonomy?) category named Gametypes. Within Gametypes I have a tag named Newest.
I am trying to get posts to display which is tagged by the Newest tag. I have tried the following code which does not work, and I am not sure why:
$args = array( 'tax_query' => array( array( 'taxonomy' => 'Gametypes', 'field' => 'slug', 'terms' => 'newest' ) ) );
$postslist = get_posts( $args );
I've tried different iterations of it with and without capital starting letter but I cannot seem to get it to work. Anyone who could shed light upon what I am doing wrong? I am able to pull every post from Reviews (posts with and without tags) with this code:
$args = array( 'post_type' => 'Reviews', 'numberposts' => 6, 'order'=> 'DESC', 'orderby' => 'date' );
In case this information helps. I hope someone can guide me in the right direction!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己找到了答案,以防有人想知道!
I found the answer myself, in case anyone wonders!
使用这个:
Use this one: