Pergunta

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..

Foi útil?

Solução

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();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange
scroll top