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:
- Using Wordpress own tools and preferences this search images meet tags in my own shortcode.
- 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”.
- 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');