Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the comments_popup_link() function to show the number of comments for each post in a loop.

<?php if (have_posts()) : while (have_posts()) : the_post();  ?>

<?php if ( get_post_meta($post->ID, 'thumb_value', true) ) : ?>
        //something
<?php else: ?>
       //something else
<?php endif; ?>


        <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 

        <?php the_content(__('Read more'));?>
        <div class="post-meta">
       <?php the_time('F j, Y'); ?>
       <p>Category: <?php the_category(', '); ?></p>
       <p><?php the_tags(); ?></p>
       <p><?php comments_popup_link('Post Comment', '1 Comment', '% Comments'); ?></p>      
    </div>


<?php endwhile; ?> 
<?php $wpdb->show_errors(); 
$wpdb->print_error(); ?>

<?php else: ?>

<p><strong>There has been an error.</strong></p>
<?php $wpdb->show_errors(); ?> 
<?php $wpdb->print_error(); ?> </p>

<?php endif; ?>

Everything displays fine but I get

WordPress database error: [] SELECT * FROM wp_comments WHERE comment_post_ID = 216 AND comment_approved = '1' ORDER BY comment_date_gmt DESC

I'm just curios why I get that..

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Your template code includes $wpdb->print_error(). This function prints the last database error between [ and ] brackets, and the executed SQL code. But if there is no error, you just see the empty brackets and the SQL.

$wpdb->show_errors() is used to enable displaying of database errors. If you want to see all database errors, you can just call this function somewhere higher in your code (in your functions.php, or in a plugin). You probably only want to do this when you are in debug mode, so it would look like this:

if ( WP_DEBUG ) {
    $wpdb->show_errors();
}
share|improve this answer
    
Oooh! Thank you for explaining :) I really concerned. lol –  wpStudent Nov 30 '10 at 18:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.