I have this function:
$ids = $wpdb->get_col("SELECT DISTINCT comment_post_ID
FROM $wpdb->comments
ORDER BY comment_date DESC
LIMIT 0 , 30");
foreach ($ids as $id) {
$post = &get_post( $id );
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
}
?>
Which shows the latest commented posts
in a list, which is fine. What I want to do is give a priority to this one and combine it with a “get newest post list
“. So let’s say I commented today on a post called Hello World and someone else submitted a post yesterday… Than I want to get the recent commented post above this new post. The problem is that in my code snippet, there is nothing that says to get the newest posts. How can I combine them? So how to combine most recent commented posts and newest posts with each other? Is this even possible?
Give it a try works perfect for me what it is doing query get the all the posts with a
left jon
withcomments
table so when a post has comment then it also has thecomment_date
if no comments posted on the post then in result set it will benull
so i have merged thecomment_date
withpost_date
so which post has the greater date (for comment_date or post_date) it will first and so onFor displaying the posts you have to first get the results by defining the WP’s global variable for the database interaction i.e
$wpdb
HTML
Hope that is what you were looking for