我需要创建一个自定义后查询循环,从各种自定义分类术语集每页与分类字段。
由于我不是一个高级的可湿性粉剂PHP开发人员,因为我需要推进项目的其他方面,我恳请你的帮助,完成建设查询。我几乎有它,但我对混合分类法,把关系和层次结构的条件块。
背景是这样的:网站是一个真实的地产经纪公司,与上市自定义职位和自定义分类提供租金/销售(categorie_offre),属性类型(type_bien)和城市(镇)。属性类型有子分类为房子,公寓,车库,一个房间,两个房间,等等。
在单页编辑器,我有我的分类ACF领域的3个分类,我决定什么术语必须过滤清单网格。
在单页模板中,现在我有这样的代码,它只适用于一个分类,但不适用于多个分类(我现在没有把城市),我认为array_merge不是好的解决方案:
我正在考虑使用这个胎面的想法,但如果一些高级开发人员可以给予我一只手,以实现它更快,我会非常非常非常感激:https://wordpress.stackexchange.com/questions/371737/how-to-get-posts-that-contain-multiple-terms-from-multiple-taxonomies
谢谢
罗兰
<?php
// Liste d'annonces pages SEO
$post_type = 'annonce';
$location_vente = get_field( 'location_ou_vente' );
$type_bien = get_field( 'type_de_bien' );
$termis = array_merge($location_vente,$type_bien);
foreach( $termis as $termi ) :
$argsi = array(
'post_type' => $post_type,
'posts_per_page' => 5,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'categorie_offre',
'field' => 'term_id',
'operator' => 'OR',
'terms' => $location_vente
),
array(
'taxonomy' => 'type_bien',
'field' => 'term_id',
'operator' => 'OR',
'terms' => $type_bien
),
),
);
endforeach;
$annonces = new WP_Query( $argsi );
// Output posts, etc.
while ( $annonces->have_posts() ) : $annonces->the_post();
the_title();
the_excerpt();
echo '<br />';
endwhile;
wp_reset_query();
?>
1条答案
按热度按时间snz8szmq1#
也许我的问题不清楚...
不管怎样,这是我找到的解决方案: