WordPress - 按标签显示自定义帖子类型 (PHP)

发布于 2025-01-10 18:09:42 字数 601 浏览 0 评论 0原文

我在让我的帖子在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不疑不惑不回忆 2025-01-17 18:09:42

我自己找到了答案,以防有人想知道!

$args = array(
  'post_type' => 'Reviews',
  'numberposts' => 6,
  'tax_query' => array(
      array(
          'taxonomy' => 'gametypes',
          'field'    => 'slug',
          'terms'    => 'newest',
      ),
  ),
);
$query = new WP_Query( $args );
$postslist = get_posts( $args );

I found the answer myself, in case anyone wonders!

$args = array(
  'post_type' => 'Reviews',
  'numberposts' => 6,
  'tax_query' => array(
      array(
          'taxonomy' => 'gametypes',
          'field'    => 'slug',
          'terms'    => 'newest',
      ),
  ),
);
$query = new WP_Query( $args );
$postslist = get_posts( $args );
听闻余生 2025-01-17 18:09:42

使用这个:

<?php
$query = new WP_Query(
    array( "post_type" => "Reviews", //  "your-post-type" !
           "tag" => "Newest"
    ) );
while ($query->have_posts()) : $query->the_post(); ?>
  
<?php endwhile; ?>

Use this one:

<?php
$query = new WP_Query(
    array( "post_type" => "Reviews", //  "your-post-type" !
           "tag" => "Newest"
    ) );
while ($query->have_posts()) : $query->the_post(); ?>
  
<?php endwhile; ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文