levani
09-08-2009, 10:41 AM
Hello,
I need small help with php. This is my code which queries latest 5 post title from database. I would like to query commented and uncommented posts separately and wrote this code:
<?php
global $wpdb;
$posts = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_author = $id AND post_type = 'post' LIMIT 5 ");
foreach ($posts as $post) {
if ($post->comment_count >= 1) {
echo '<li>' . $post->post_title . '</li>';
}
else if ($post->comment_count < 1) {
echo '<li>' . $post->post_title . '</li>';
}
}
?>
But there is one big problem. If the latest five posts are all uncommented when I view commented posts it doesn't display anything. I know that it happens because of comparing comments number to 1 and showing posts only after it, but I don't know any better ways.
Can anyone please help?
I need small help with php. This is my code which queries latest 5 post title from database. I would like to query commented and uncommented posts separately and wrote this code:
<?php
global $wpdb;
$posts = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_author = $id AND post_type = 'post' LIMIT 5 ");
foreach ($posts as $post) {
if ($post->comment_count >= 1) {
echo '<li>' . $post->post_title . '</li>';
}
else if ($post->comment_count < 1) {
echo '<li>' . $post->post_title . '</li>';
}
}
?>
But there is one big problem. If the latest five posts are all uncommented when I view commented posts it doesn't display anything. I know that it happens because of comparing comments number to 1 and showing posts only after it, but I don't know any better ways.
Can anyone please help?