ACF multi taxonomy on filterable gallery
I created a filterable gallery with ACF. My problem is that when I add a project to which I add several taxonomies, in my gallery I have the project as many times as I have added taxonomies. Apart from that, I would like the project to appear only once in the gallery but to appear in all the filters where the taxonomy is selected.
div id=filters class=col-3
ul class=nav
li data-filter=all class=filter activeTous les projets/li
?php
// 1. On définit les argument pour définir ce que l'on souhaite récupérer
$args = array (
'post_type' = 'projet'
);
$terms_id = [];
// 2. On execute la WP query
$my_query = new WP_Query( $args );
// 3. On lance la boucle
if ($my_query-have_posts()) : while($my_query-have_posts()) : $my_query-the_post();
$categories_du_projet = get_field( 'categories_du_projet' );
if ( $categories_du_projet ) : ?
?php foreach ( $categories_du_projet as $term ) :
if (!in_array($term-term_id, $terms_id)) :
array_push($terms_id, $term-term_id);
?
li data-filter=?= esc_html( $term-slug ); ? class=filter?= esc_html( $term-name ); ?/li
?php endif; endforeach; endif; endwhile; endif;
// 4. On réinitialise la requete principale
wp_reset_postdata();
?
/ul
/div
div id=elements class=col-9
?php
// 1. On définit les argument pour définir ce que l'on souhaite récupérer
$args = array (
'post_type' = 'projet'
);
// 2. On execute la WP query
$my_query = new WP_Query( $args );
// 3. On lance la boucle
if ($my_query-have_posts()) : while($my_query-have_posts()) : $my_query-the_post();
$categories_du_projet = get_field( 'categories_du_projet' );
$image_du_projet = get_field( 'image_du_projet' );
$titre_du_projet = get_field( 'titre_du_projet' );
$titre_du_projet = preg_replace('/\s+/', '_', strtolower($titre_du_projet));
$trigger_ID = 'trigger_' . $arr_posts-current_post . '_' . get_the_ID();
$modal_ID = 'modal_' . $arr_posts-current_post . '_' . get_the_ID();
$close_ID = 'close_' . $arr_posts-current_post . '_' . get_the_ID();
$image_ID = 'grandeImage_' . $arr_posts-current_post . '_' . get_the_ID();
$images = acf_photo_gallery('galerie_du_projet', $post-ID);
if ( $categories_du_projet ) :
foreach ( $categories_du_projet as $term ) :
if ( $image_du_projet ) :
?
div class=?= esc_html( $term-slug ); ?
figure class=trigger id=?php echo $trigger_ID ?
img src=?php echo esc_url( $image_du_projet['url'] ); ? alt=?php echo esc_attr( $image_du_projet['alt'] ); ? /
figcaption?php the_field( 'titre_du_projet' ); ?/figcaption
/figure
/div
?php endif; ?
div class=modal id=?= $modal_ID ?
div class=modal-content
span class=close-button id=?= $close_ID ?times;/span
h2?= get_field( 'titre_du_projet' ); ?/h2
hr
div class=row
div class=image
?php $image_du_projet = get_field( 'image_du_projet' ); ?
?php if ( $image_du_projet ) : ?
img class=?= $image_ID; ? src=?= esc_url( $image_du_projet['url'] ); ? alt=?= esc_attr( $image_du_projet['alt'] ); ? /
?php endif; ?
img class=grandeImage /
div class=row id=gallery-full
?php
//Check if return array has anything in it
if( count($images) ):
//Cool, we got some data so now let's loop over it
foreach($images as $image):
$id = $image['id']; // The attachment id of the media
$title = $image['title']; //The title
$caption= $image['caption']; //The caption
$full_image_url = $image['full_image_url']; //Full size image url
//Resized size to 262px width by 160px height image url
$thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
$url= $image['url']; //Goto any link when clicked
$target= $image['target']; //Open normal or new tab
$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
$class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
?
div class=thumbnail
img id=image_?= $id; ? src=?= $full_image_url; ? alt=?= $title; ?
/div
?php endforeach; endif; ?
/div
/div
div class=description
h3Description/h3
p?php the_field('description_du_projet'); ?/p
/div
/div
/div
/div
All I want is just no duplicate pictures on all project just one picture, not one per taxonomies. If anyone can help me please... Too much time on it and I found nothing to help me.
This is my var_dump($term) and on this 3 pictures only one can display the modal.
I want on All project display just one picture and when I choose one of the 3 filters, can click on it and display the modal
Topic advanced-custom-fields multi-taxonomy-query custom-field Wordpress
Category Web