EDIT: I saw that as of version 2.0.30, the problem has been solved!
For everyone using an older version:
The problem is, that the tags created for pictures are saved as slugs. So if you have a page or category or anything with the same slug, wordpress will save one of them as “myslug” and the other one as “myslug2”, numbering up at the end, if the slug already exists.
So for the situation at hand: If your chapter / page etc. has the slug, say, “foxtrotting”, if you now define the “foxtrotting” tag for your pictures in the nextgen gallery, they will get the wordpress-internal slug “foxtrotting2”. Now when the nextgen gallery goes looking for the “foxtrotting” slug, it will return the entry of the chapter / page, not the images (which have received the slug “foxtrotting2”)!!
Everything clear so far?
So what I have done is change the relevant MySQL select withing the nextgen gallery, so that the correct entries are returned, not the mistaken ones:
I’ve done the change for nextgen gallery 2.0.23. With a quick look at the previous ones (going back to the 1.9.*) they seem have the same issue.
Now for the fix
The file we’ll be working with is:
nextgen-gallery/products/photocrati_nextgen/modules/nextgen_gallery_display/class.displayed_gallery.php
On line 724 we find the function get_term_ids_for_tags
In this function there are 2 lines we want to modify:
Replace
$container_ids[]= "'{$container}'";
with
$container_ids[] = "slug LIKE '%%$container%%'";
And replace
$query = $wpdb->prepare("SELECT term_id FROM $wpdb->terms WHERE slug IN ({$container_ids}) ORDER BY term_id ASC ", NULL);
with
$query = $wpdb->prepare("SELECT term_id FROM $wpdb->terms INNER JOIN $wpdb->term_taxonomy USING (term_id) WHERE ($container_ids) AND taxonomy = 'ngg_tag' ORDER BY term_id ASC ", NULL);
So what we’re doing here is changing the MySQL select statement from searching for the exact tag (i.e. “foxtrotting”), to being more open and also allowing entries that merely contain the exact tag (i.e. “foxtrotting2”). Then we check the ‘term_taxonomy’ table to see which ones belong to the nextgen gallery and return those.
Voilà! Hope that solves the problem.
If you have any questions or anything, just let me know.