Support » Plugins » Developing Plugin; Strange Global $wpdb Error

  • Resolved skicrave


    I’m writing a little plugin to make use of shortcodes, but I’m having a problem with the output.

    • If I don’t declare $wpdb as global in the function then I get a call to function error
    • If I do declare $wpdb as global in the fuction I get the URI to my blog repeated six times as the first output from the_content().

    Here is the code I have in my plugin file:

    // [insertgallery id="38"]
    function insert_gallery($attr) {
    	global $wpdb, $tableposts;
    	// Get the info for the gallery from the database
    	$sql = "SELECT wo_fim_cat.folder, wo_fim_cat.catname, wo_fim_images.image FROM wo_fim_cat LEFT JOIN wo_fim_images ON WHERE wo_fim_cat.status= 'public' AND = $attr[id] LIMIT 0,3";
    	$gallerydata = $wpdb->get_results($sql);
    	// Loop through the output
    	foreach ($gallerydata as $gallery):
    		$output .= "<a href='";
    		$output .= bloginfo('home');
    		$output .= "/photos/album/$gallery->folder' title='View The ";
    		$output .= $gallery->catname;
    		$output .= " Image Gallery'><img src='";
    		$output .= bloginfo('home');
    		$output .= "/wp-content/fgallery/$gallery->folder/thumb_$gallery->image' style='padding:1px;' alt='$gallery->catname Image Gallery' /></a>";
    	return "<b>Gallery:</b> <a href='$gallery->folder'>$gallery->catname<br />$output";
    add_shortcode('insertgallery', 'insert_gallery');

    It’s working exactly as I want, with the exception of the repeating blog URI that is being injected in front of the content. Here’s a screen shot of what it looks like.

    Any ideas what might be causing this, and how to prevent the blog URI from displaying repeatedly?

Viewing 2 replies - 1 through 2 (of 2 total)
  • bloginfo() echoes the returned value every time you call it.
    If you want to get the value, use get_bloginfo('home') instead.

    $wpdb isn’t the point. As you already clarified, you need to declare global $wpdb to use.

    You’re absolutely right! I realized that just before you posted your reply. It’s all squared away now, thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Developing Plugin; Strange Global $wpdb Error’ is closed to new replies.