[wp-hackers] hooks on the Loop

Andy Skelton skeltoac at gmail.com
Thu Jul 13 01:11:35 GMT 2006


I don't normally do this because people ask too many questions once
you start feeding them code, but you won't ask any more questions
after this, right? ;-)

// Checks cookie or whatever, returns bool
function is_recently_commented() { ... }

// Returns array of post ID's using this:
// SELECT MAX(comment_date) as date,
//  comment_post_id
// FROM $wpdb->comments
// WHERE comment_approved = '1'
// GROUP BY comment_post_ID
// ORDER BY date DESC
function get_recently_commented() { ... }

// Filters the main query AND
function whatever($q) {
 global $wpdb;
 if ( is_recently_commented() ) {
  $ids = join(', ', get_recently_commented());
  return "$q AND ID IN ($ids)";
 } else
  return $q;
 }
}
add_filter('posts_where_paged', 'whatever');

No warranties expressed or implied,
Andy

On 7/12/06, Aaron Brazell <emmensetech at gmail.com> wrote:
> On 7/12/06, Andy Skelton <skeltoac at gmail.com> wrote:
> >
> > No... you should start dissecting WP_Query with your own two hands.
> > It'll be a lot less confusing when you find out what's actually being
> > passed around by these filters and how you can affect the process.
> >
> > Try something like die(print_r($this->request, true)) just before the
> > get_results call (maybe line 921) of query.php.
> >
> > No amount of advice from me or someone else can compare to a little
> > first-hand experience.
> >
> >
> Thanks, Andy. I appreciate it. But you know... I've dissected WP_Query and
> can't find a real reasonable way to get posts that have recent comments.
> Heck, even if there was a way to pass a direct query to query_posts() I
> could work up some query similar to the dozen and a half "recent comments"
> plugins, but I don't even think I can directly pass SQL.
>
> --
> Aaron Brazell
> Author & Blogger, http://technosailor.com
> Systems Admin, http://b5media.com
> Sports Channel Editor, http://b5media.com
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list