Support » Fixing WordPress » Query doesn’t returns expected values

  • Resolved J_25


    I have the following function that’s supposed to return a list of posts that have a comment count grater than 1 let’s say. I want to use this function to display a list of hot post.
    The problem is that it doesn’t outputs anything…why? I run the query in MySqlYOG and the query works just fine…

    function custom_GetHotTopics( $limit=10 )
    	global $wpdb;
    	$sql = "SELECT ID, post_title FROM wp_posts
    			WHERE post_status='publish' AND post_type='post'
    			HAVING comment_count > 1
    			ORDER BY comment_count DESC LIMIT ".$limit;
    	$results = $wpdb->get_results($sql);
    	$output = '';
    	foreach ($results as $result)
    		$title = strip_tags($result->post_title);
    		$output .= '<li><a href="index.php?p='.$result->ID.'">'.$title.'</a></li>';
    	echo $output;
  • The topic ‘Query doesn’t returns expected values’ is closed to new replies.