I’m trying to run a custom query against the WordPress database in order to get an individual gallery for an individual post. I need to do this as a one off process to update the database – I can’t just do this in a template. The gallery ID in the wp_ngg_gallery
table does not appear to be associated via a key in the wp_postmeta
table.
I’ve tried some remote debugging via Xdebug but can’t find the relevant code – the plugin has a lot of classes and files.
The post contains markup similar to the following:
<img class="ngg_displayed_gallery mceItem" src="http://nameofmysite/nextgen-attach_to_post/preview/id--8259" alt="" data-mce-placeholder="1" />
This seems to get replaced by the nextgen plugin with the appropriate gallery. Older posts have a shortcode but a number of them don’t ; I need to replace an element on each individual post page with a random image from a nextgen gallery – hence the need for a custom query.
I can see the following query being run on the page which seems relevant but the gallery id value (gid) is already known:
SELECT DISTINCT wp_ngg_gallery.* , GROUP_CONCAT(CONCAT_WS('@@', meta_key, meta_value)) AS 'extras'
FROM `wp_ngg_gallery`
LEFT
OUTER JOIN `wp_postmeta`
ON `wp_postmeta`.`post_id` = `extras_post_id`
WHERE (`gid` = 311)
GROUP BY wp_ngg_gallery.gid
LIMIT 1
This question would not be suitable for WordPress.stackexchange as they do not allow questions about specific plugins.
the mechanism I need to understand is the ATP placement code described here: