query_posts with date custom field
-
I have to present posts in order according to a custom field that is a date.
Currently, I have the custom field (named ‘Event Date’) as a simple text (eg: “12/31/2010”, “1/4/2011” – quotes not-withstanding).
My special page uses this code to get the posts:$pageNumber = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'posts_per_page' => 2, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => 'Event Date', 'paged' => $pageNumber, 'category_name' => 'Events' ));
Of course (as the Codex points out) “the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers”
Been reading around and found a few pointers on alternatives, but they all seem to either go for a more complex solution than I’d like to have.
So… what’s the easiest option for me to get the proper order (by date, earliest date first) ?
A) This option uses the Flutter plugin to handle the cusom field, then uses the code from this post (adding 5 filters)
B) This option uses a single filter (on ‘posts_where‘)
C) This one uses the date() cast on the meta_value argument – but also hooks into the ‘save_post‘ action to use the same casting on the way in.
D) Those that worked on this thread are building the proper query_string – but then I’d have to abandon the use of query_posts…
Suggestions? Thanks in advance
- The topic ‘query_posts with date custom field’ is closed to new replies.