[wp-hackers] Pull Latest Post from Each of 6 Categories
mikeschinkel at newclarity.net
Tue May 5 04:29:15 GMT 2009
> At the very least, this points out a limitation in the WP_Query object
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.
From: "Paul" <paul at codehooligans.com> wrote:
> 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.
Paul, I think this does point out a limitation of the WP_Query object. WP_Query is a great example of an ad-hoc attempt to isolate and simplify usage of a language that has had many orders of magnitude more engineering time devoted to it's design than that which isolates it. You can see such attempts all over computing, most developers do it, and I know myself I've created many a straw house attempting to simply other things most notably when I tried to create an ActiveX object for use in ASP programming to abstract generation on an HTML table.
Another great example of this approach is wiki-language that tries to simplify HTML. Has anyone tried to do anything advanced on Wikipedia? I daresay that what replaced it was far worse that what it was replacing and it's a shame we don't all just try to promote learning of HTML.
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.)
> 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.
I don't think that is a valid defense of WP_Query(). There is no alternate in the WordPress API for doing things more complex which results in people complaining about not using the WordPress API (even though it's not properly suited for the use-case), which is all a vicious circle.
What's the broader solution?
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.
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.
Custom Wordpress Plugins
More information about the wp-hackers