我正在尝试为那些在tax_query中有term1和在taxonomy2中有term2的帖子做taxonomy1
如果我这样做了:
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'taxonomy1',
'terms' => 'term1',
],
[
'taxonomy' => 'taxonomy2',
'terms' => 'term2',
],
],我所有的帖子都是用term1写的,taxonomy1是用term2写的,也是用taxonomy2写的。我想要包含两个术语的帖子: term1和term2。
谢谢。
<#>
首先,我恢复“链接类别”的所有术语,并将其传递给模板:
public function links()
{
$terms = get_terms(array(
'taxonomy' => 'link-category',
'hide_empty' =>true,
));
return $terms;
}然后,在模板中,我用foreach循环它:
@if (!empty($links))
@foreach ($links as $link)
@php
$args = [
'post_type' => ['links'],
'post_status' => 'publish',
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'link-category',
'terms' => $link,
],
[
'taxonomy' => 'despacho',
'terms' => $despacho,
],
],
];
$link_posts = new WP_Query($args);
@endphp
@if ($link_posts->have_posts())
{{ $link->name }}
@while ($link_posts->have_posts()) @php $link_posts->the_post();
$link = get_field('url') @endphp
{{ $link['title'] }}
@endwhile
@endif
@endforeach
@endif这段代码收集了一个名为"link“的CPT,以显示在这个页面的页脚:https://stage.superbiajuridico.es/中。
这是页脚的外观:

发布于 2020-03-02 07:30:44
正如jdm2112和SallyCJ在评论中所说的那样,查询缺少'field' => 'slug'。所以:
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'link-category',
'terms' => $link,
'field' => 'slug'
],
[
'taxonomy' => 'despacho',
'terms' => $despacho,
'field' => 'slug'
],
],https://wordpress.stackexchange.com/questions/359791
复制相似问题