[wp-hackers] hooks on the Loop

David Chait davebytes at comcast.net
Thu Jul 13 05:13:05 GMT 2006


Try it in two passes -- at least that's how I would...  Query the comments 
table for unique/dinstinct post ID, order by comment time, limit N.  Then 
query the posts table with all the standard rules/where/filters, with the 
addition of "AND ID in (...comma'd list of IDs from the comments query...)". 
Well, something like that.  You could likely do it with a join, but would be 
N*M at the least...  A subquery is what you really want, do it all in one, 
optimized, query call -- but only more recent MySQL supports that (if I 
remember correct).

If you wanted to 'plug it in' to the current system, depends on the desired 
result.  Hooking the main query setup, doing the comments query yourself, 
then adding the ID list to the WHERE clause... well, it ain't pretty, but it 
should work.  If you then 'paged' through the system normally, you'd want to 
run the comments query again but do a limit X,Y to jump through the results. 
(I believe I do something similar in a number of the CG-Referrer filtered 
queries, but haven't looked at the code in a while!)

-d

----- Original Message ----- 
From: "Aaron Brazell" <emmensetech at gmail.com>
To: <wp-hackers at lists.automattic.com>
Sent: Wednesday, July 12, 2006 7:58 PM
Subject: Re: [wp-hackers] hooks on the Loop


| 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.



More information about the wp-hackers mailing list