[wp-hackers] Pull Latest Post from Each of 6 Categories

Nathan Rice ncrice at gmail.com
Tue May 5 04:46:39 GMT 2009

On Tue, May 5, 2009 at 12:29 AM, Mike Schinkel
<mikeschinkel at newclarity.net>wrote:

> I'm not sure this is a correct statement. Sure, WP_Query does not
> provide the flexibly needed for this specific needs. I do think
> WP_Query is somewhat state of the art in it's design. It's just that
> the author(s) did not anticipate your needs when creating it. If you
> think about how WP is mostly used it's more for getting a list of
> items based on time sorting. In your case you want only one post from
> each category which break its model.

Don't get me wrong. I'm not blaming anyone for not anticipating my specific
use-case. That would be stupid. I'm just saying that this could be an
opportunity for the WP_Query class to get better.  The site I'm maintaining
is a new-style site that has a content heavy homepage. It relies heavily on
categories to pull content, and it would be nice if the WP_Query class would
allow me to pull latest story(ies) from multiple categories with as few
queries as possible. From what I hear, the WordPress bottleneck is always
the database, so I want certainly don't want to aggravate that by being

> So WP_Query() is by definition limited in it's ability to model SQL with
> fidelity and unfortunately, always probably will be. It does have benefits
> in that it abstracts the SQL queries so that the data models can change
> (slightly) but it will never be able to do everything that SQL can do
> (unless it was modeled to be as thin a layer on SQL as possible thus
> reducing it's ability to shield against changes.)

I'm definitely glad WordPress provides functions and classes that pull data
from the database. PHP + SQL is not something I'm interested in learning at
the moment, despite the fact that I'm sure it would be good for me.

But I do see your point. Compensating for the uneducated can place
limitations on things, that's for sure.

>  1.) Nathan should just hack the SQL for his specific site and put code in
> place to fallback when a new version of WP is installed.
> 2.) The WordPress team should either rearchitect WP_Query() or add another
> function that can handle these really complex use-cases.
> I'd be happy to help with #2 is this were a forum for dialog on improving
> the core but my past experience is that it is not so I won't bother and I'll
> just hack SQL code when I need it.

>From what I can tell, not much NEW functionality has been added to the class
in a while.  It would be nice to get new features and parameters that would
address these specific use cases, especially considering the prevalence of
WordPress being used to run large news sites.  There CAN'T be any weak
points when traffic surges. Performance is a HUGE deal.

> Nathan, if you need help with SQL that's at least one thing I'm really good
> with. Contact me offline and I can help.

I appreciate that.  For now, I'm going leave it as-is and hope that
wp-super-cache keeps us above water. If it doesn't, you'll definitely be
hearing from me :-)


More information about the wp-hackers mailing list