[wp-hackers] sticky for custom post types
wordpress at zed1.com
Sat Mar 5 12:06:52 UTC 2011
On 5 March 2011 11:52, Steve Taylor <steve at sltaylor.co.uk> wrote:
> I have a plugin
> (http://sltaylor.co.uk/wordpress/plugins/slt-custom-fields/) to manage
> custom fields, so of course this is a fallback. The issue, as you say,
> is that you potentially need to do 2 queries - one to get "promoted"
> items, and one to get the latest ones if there's no enough that are
> promoted. I've got tabs on the home page with 4 different content
> types to pull through, which comes to up to 8 queries.
> Of course caching (with transients or with a plugin) will remedy this
> to a degree. But it still all feels like working around a simple
> omission in the CPT spec :-/
I think the CPT spec, as much as there was one, specifically had that CPTs
were not meant to be chronological. The whole point of 'sticky' is that it
is a way to circumvent the built in chonology of the default listing. If
CPTs don't have a built in chronology (and they don't) then sticky doesn;t
But they are custom so you can choose to add in chronology, and this the
idea of sticky.
Anyway to be constructive: I think if you were to add metadata with a key of
'promoted' (or even 'sticky') and give it a numerical value; you could sort
by that meta value in the same query that retrieves all your properties.
Those fields without the key should evaluate to 0 (if not add the key with a
zero value by default).
I think in 3.1 you can even sort by value with custom taxonomies.
Hope that helps,
More information about the wp-hackers