How to use Justified Image grids: tags with AND

After 2 hour session with google no answer to this question:

[justified_image_grid image_tags=“BticinoSferaNew,painikealue_1-10” image_categories=tuotekuva]

BticinoSferaNew AND painikealue_1-10. So, look inside JIG is any bug, it use “OR”. Typically I never need this function. Always AND. So, how I can adjust jig use AND in tags? “Show only images contain BticinoSferaNew AND painikealue_1-10”.

So: How I can use AND in JIG tags? This answer not in FAQ and also not in any documentation.

You will need code modification. If you’re looking for freelancer, I’m available, you can contact me anytime

Problem solved. Of course consult with chatgpt…

First at all, I create child theme. It is not mandatory, but make work much easy.

Then I create my own shortcut:
[justified_image_grid_jukka tags=“tag1,tag2,tag3” tags_operator=“AND” not_tags=“tag5” categories=“productphoto”]**

So, this is my own shortcut named “justified_image_grid_jukka”. Use is simply tag1 AND tag2 AND tag3 etc, also I exclude-possibility.

How this work?
In nutcell:

  1. Using Wordpress own tools and preferences this search images meet tags in my own shortcode.
  2. Shortcode create internal list of the image ID:s. So. Shortcode only “work” is build image ID numbers meet tags… so this accept “AND”, “OR” and “EXCLUDE”.
  3. Then shortcut code put this image number list to JIG. [justified_image_grid ids=“4001,4002,4006 etc”].

After big work I understand JIG is only gallery shortcut. It contain only very simplified image select tool but extemely good visual tools to gallery. So- it can make gallery only using list of images or tags, but all clever tool (AND, eg.)—nada.

So. Using shortcode “image_justified_gallery_jukka” we can collect image ID:s. It is also make this type also to other use- eg. complicate taxonometry etc. Then this code put it image ID list to JIG, and create gallery. Sorry. COmments are not lingua franca reason I build this with finnish…

function justified_image_grid_jukka_shortcode($atts) {
    // Oletusasetukset lyhytkoodille
    $atts = shortcode_atts(
        array(
            'tags' => '',
            'tags_operator' => 'OR',
            'not_tags' => '',
            'categories' => '',
        ),
        $atts,
        'justified_image_grid_jukka'
    );

    // Haetaan ja käsitellään lyhytkoodin attribuutit
    $tags = explode(',', $atts['tags']);
    $tags_operator = $atts['tags_operator'];
    $not_tags = explode(',', $atts['not_tags']);
    $categories = explode(',', $atts['categories']);

    // WP_Query kustomointi
    $args = array(
        'post_type' => 'attachment', // Koska JIG käyttää mediaa (kuvia)
        'posts_per_page' => -1, // Näytetään kaikki
        'post_status' => 'inherit',
        'tax_query' => array(
            'relation' => 'AND', // Kaikki ehdot täytyttävä
        ),
    );

    // Lisää tagit, jos niitä on
    if (!empty($tags)) {
        foreach ($tags as $tag) {
            $args['tax_query'][] = array(
                'taxonomy' => 'post_tag',
                'field' => 'slug',
                'terms' => $tag,
                'operator' => 'IN',
            );
        }
    }

    // Lisää kategorian suodatus
    if (!empty($categories)) {
        foreach ($categories as $category) {
            $args['tax_query'][] = array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => $category,
                'operator' => 'IN',
            );
        }
    }

    // Muokataan WP_Query:n perusteella
    $query = new WP_Query($args);

    // Jos ei löydy kuvia, palautetaan viesti
    if (!$query->have_posts()) {
        return 'Ei kuvia löydy.';
    }

    // Kerätään kuvien ID:t taulukkoon
    $image_ids = array();
    while ($query->have_posts()) {
        $query->the_post();
        $image_ids[] = get_the_ID();
    }

    // Resetoi postdata
    wp_reset_postdata();

    // Muodostetaan JIG-shortcode
    $ids_string = implode(',', $image_ids);
    return do_shortcode('[justified_image_grid ids="' . $ids_string . '"]');
}

add_shortcode('justified_image_grid_jukka', 'justified_image_grid_jukka_shortcode');


It sounds like you’re trying to filter images in a Justified Image Grid (JIG) based on multiple tags with an AND condition, but JIG defaults to using an OR condition between tags. Unfortunately, JIG’s standard functionality uses OR for tags, which means it will show images that contain either tag, not necessarily both. Office 2021 Activador Download

Yes. This I know. This is most big bug in Justified Image Grid. I really cannot understand it :). And, I cannot imagine ANY case, when image select need OR. No any case, when it need… so this is most big bug in JIG, and never fixed.