Hi,
I need to create a custom post query loop from various custom taxonomy terms set per page with taxonomy fields.
As I am not a senior WP PHP developper, and as I need to move forward on other aspects of the project, I kindly ask you for your help to finish building the query. I almost have it but I am blocking on mixing taxonomies, put relationnal and hierarchical conditions.
The context is this: Website is for a real estate agency, with listing custom posts and custom taxonomies for offer rent/sale (categorie_offre), property type (type_bien) and city (ville). Property type has child taxonomies for Houses, appartments, garage, 1 room, 2 rooms, etc.
In single page editor, I have my taxonomies ACF fields for the 3 taxonomies where I decide what term must filter the listing grid.
In single page template, for now I have this code, that work for only one taxonomy, but not for multiple (I didn’t put cities for now), I think array_merge is not the good solution:
<?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();
?>
I am thinking of using the idea of this tread but if some senior developper could give me a hand to achieve it quicker I would be very very very thankfull:
https://wordpress.stackexchange.com/questions/371737/how-to-get-posts-that-contain-multiple-terms-from-multiple-taxonomies
Thanks
Roland