ShortCodes, MySQL, (Newbie problem)
-
This is my first attempt to play with ‘shortcodes’ and reading the database directly.
I am trying to get the details of piccies from a nextGEN gallery, so that I can display them in my own (to be coded yet) javascript routine.
I have tested the shortcode without the SQL bit and it worked.
I have displayed the SQL string to the screen and I have copied and pasted that into phpMyAdmin and that works.
But that is as far as it gets. The SQL bits are not working and it never reaches the return at the end of the shortcode function.
I got the basis of the following code from a site I googled.
I am very new to all this, so I expect I have missed something simple, but any advice or pointer to my mistakes would be appreciated.
Richard
Running v2.9.2 on a hosted site.
functions.php ----------------------- function galleryPics($gallery=1) { include_once(‘wp-config.php’); include_once(‘wp-load.php’); include_once(‘wp-includes/wp-db.php’); echo "RUNNING gPics (function galleryPics)" . "<br />"; $sqlQuery = "SELECT wp_ngg_gallery.path, wp_ngg_pictures.filename, wp_ngg_pictures.description, wp_ngg_pictures.alttext FROM wp_ngg_gallery, wp_ngg_pictures WHERE wp_ngg_gallery.gid = wp_ngg_pictures.galleryid and wp_ngg_gallery.gid = 1 order by wp_ngg_pictures.sortorder ASC"; echo "SQL: " . $sqlQuery . "<br />"; $resultPics = $wpdb->get_results($sqlQuery); foreach ($resultPics as $pic) { echo "PATH: " . $pic->path . "<br />"; echo "FILENAME: " . $pic->filename . "<br />"; echo "DESC: " . $pic->description . "<br />"; echo "ALT: " . $pic->alttext . "<br />"; } $pics = "List of Thumbnails" . "<br />"; return $pics; } add_shortcode('gPics', 'galleryPics'); Shortcode ----------------- [gPics] Output from Post ------------------------ RUNNING gPics (function galleryPics) SQL: SELECT wp_ngg_gallery.path, wp_ngg_pictures.filename, wp_ngg_pictures.description, wp_ngg_pictures.alttext FROM wp_ngg_gallery, wp_ngg_pictures WHERE wp_ngg_gallery.gid = wp_ngg_pictures.galleryid and wp_ngg_gallery.gid = 1 order by wp_ngg_pictures.sortorder ASC
The topic ‘ShortCodes, MySQL, (Newbie problem)’ is closed to new replies.