Ok, so I'm using the WPAlchemy class to create custom field write panels in the write post page, and so far everything has gone great... However, there's one issue I can't seem to figure out. I'm trying to use the custom field values of "event dates" to sort events on a custom page template.
I followed the instructions "Query based on Custom Field and Sorted by Value" found in the codex to try and setup the custom query, but it doesn't seem to be working?
Here's the code from the custom page template for the "Events" page:
<?php
/*
Template Name: Events
*/
get_header();
?>
<div id="depthead" class="grid_12">
<h2>Upcoming Events</h2>
</div><!--/depthead-->
<?php
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = '_events_meta[event_date]'
AND wposts.post_type = 'post'
ORDER BY wpostmeta.meta_value DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
<?php if ($pageposts): global $post; $cnt=0; foreach ($pageposts as $post): $cnt++; setup_postdata($post); ?>
<div id="article-<?php echo get_the_ID(); ?>" class="listingbox grid_3">
<div class="deptpostimg">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><img src="<?php echo $events_metabox->get_the_value('event_thumbnail'); ?>" style="outline:1px solid #000" alt="<?php the_title_attribute(); ?>" /><span class="event-date"><?php $events_metabox->the_value('event_date'); ?></span></a>
</div><!--/deptpostimg-->
<h4 class="listing-titles"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
<div class="excerpt">
<?php the_excerpt(); ?>
</div><!--/excerpt-->
</div><!--/article-<?php echo get_the_ID(); ?>-->
<?php if($cnt % 4 == 0) { ?>
<div class="grid_12 rowseparator">
<hr />
</div><!--/rowseparator-->
<?php } ?>
<?php endforeach; endif; ?>
</div><!--/wrapper-->
<?php get_footer(); ?>
It's like it's not picking up the custom field keys... The class I'm using to create these custom write panels stores them all as an array, hence the reason I've attempted to access them by using: _events_meta[event_date]
Maybe that's the problem, but I don't know how to fix it if it is...
Any ideas?
EDIT: Here's an image so you can see just how the custom fields are stored in the database. Hopefully that helps you figure out why on earth _events_meta[event_date]
won't work in the query?