errore del database WP per comments_popup_link ()
Domanda
Sto usando la funzione comments_popup_link()
per mostrare il numero di commenti per ogni post in un ciclo.
<?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; ?>
visualizza tutto bene ma ottengo
errore del database di WordPress: [] SELECT * DA DOVE wp_comments comment_post_ID = 216 e comment_approved = '1' ORDER BY DESC comment_date_gmt
Sono solo curioso il motivo per cui l'ho capito ..
Soluzione
Il codice modello include $wpdb->print_error()
. Questa funzione stampa l'ultimo errore del database tra [
e staffe ]
, e il codice SQL eseguito. Ma se non ci sono errori, basta vedere le parentesi vuote e SQL.
$wpdb->show_errors()
viene utilizzato per abilitare la visualizzazione di errori del database . Se volete vedere tutti gli errori del database, si può chiamare questa funzione da qualche parte più alta nel vostro codice (nel vostro functions.php
, o in un plugin). È probabilmente solo vuole fare questo quando si è in modalità debug, quindi sarebbe simile a questa:
if ( WP_DEBUG ) {
$wpdb->show_errors();
}