gpt4 book ai didi

php - 在循环中显示自定义分类 Wordpress

转载 作者:搜寻专家 更新时间:2023-10-31 20:35:24 24 4
gpt4 key购买 nike

好的,这可能很简单。但出于某种原因,我似乎无法弄明白。

我有一个名为:Beachevents 的自定义帖子类型。我有几个事件。我还有一个名为:Thema 的自定义分类法。

在制作 beachevent 页面(不是帖子)时,我创建了一些类型的 thema(主题)。比如:Strand Spellen(鼻涕虫是 strand-spellen)。

现在我想制作一个循环,显示带有缩略图和所有其他内容的唯一 strand-spellen。

有人知道我是怎么做到的吗?

我尝试了一些类似的代码,但没有成功。

$args = array(
'post_type' => 'beachevents',
'posts_per_page'=> -1,
'tax_query' => array(
array(
'taxonomy' => 'strand-spellen',
'field' => 'slug',
'terms' => 'all'
)
)
);
$products = new WP_Query( $args );
if( $products->have_posts() ) {
while( $products->have_posts() ) {
$products->the_post();
?>

<div class='content'>
<h2><?php the_title(); ?></h2>
</div>
<?php
}
}
else {
echo 'There seems to be a problem, please try searching again or contact customer support!';
}

谢谢!

最佳答案

你很接近!

在您的 tax_query 中,taxonomy 需要引用“beachevents”,terms 需要引用“strand-spellen”。

因此,您的代码将如下所示:

    'tax_query' => array(
array(
'taxonomy' => 'thema',
'field' => 'slug',
'terms' => 'strand-spellen'
)
)

有关构建查询的更多信息,您可以找到 WP_Query documentation有用 - 那里有一个关于分类查询的部分。

关于php - 在循环中显示自定义分类 Wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36858459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com