wpdb->get_results only works in some themes
-
Hey, I’m updating my blog from an older version of wordpress, and our comments section stopped functioning after updating.
I think I’ve traced down the problem to comment-template.php, where the following code is run:
if ( $user_ID) { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, $user_ID)); } else if ( empty($comment_author) ) { $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') ); } else { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email)); }
For some reason, this code returns $comments as an empty array in my theme, and returns an array of length 3 in the official wordpress theme TwentyEleven, even though they receive the exact same query text (it enters the first if-block).
Do I need to initialize $wpdb somewhere? Is there some variable or function that needs to be called or set before I get to this call in the code?
Thanks for any help.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘wpdb->get_results only works in some themes’ is closed to new replies.