I'm trying to do a custom query for a volunteer site I'm doing. Basically, I will be adding a custom meta_key to particular posts. These posts will be written once a month, so the custom meta key has a value of the current month and year. (In other words, when someone writes a post, the will select the meta key of "month_year") and type in the month and year they want to display in. The next article they write will be posted for October, so if they write it *today*, they will be inputting "October 2007")
What I need to do is to a custom query for a certain Page on the site. I found this thread, which has got me started on things. Right now, it's sucessfully working: when I put in the "month_year" meta key, and I've entered in "September 2007", *only* the posts with the meta key put in are showing up. That's awesome.
However, now I need to get the query to go a step or two further. I need the Page in question to:
1) display *all* posts with the custom meta key set (the rest of the site is currently set to only show 10 posts at a time)
2) take the posts with the custom meta_key set, and keep them together by month (meaning, display all of "September 2007" together, "October 2007" together, and so on)
3) If possible, I'd like to also create a custom key that would generate a "links list" to archive these posts by month (so I can display the current month on the Page, but in the sidebar, have a list of the previous months)
I *think* I can get #1, and I believe if I can get help with #2, then I could figure out #3. But any input on any of these would be great.
Oh, and here's the code that's working right now:
<?php if (is_page('12')) {
$pageposts = $wpdb->get_results("SELECT *
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'month_year'
ORDER BY post_date DESC", OBJECT);
if ($pageposts) : foreach ($pageposts as $post): setup_postdata($post); ?>
//post stuff here
<?php endforeach;?>
<?php endif; } ?>