I'm looking to return all custom field values within a certain time frame, i.e. every custom value for key X within the last month. Is this possible?
I'm looking to return all custom field values within a certain time frame, i.e. every custom value for key X within the last month. Is this possible?
Here is some sample code that might help:
$meta_key = 'Favorite Fruits';
$start_date = '2010-11-09 00:00:00';
$end_date = '2010-11-12 23:59:59';
$sql = "SELECT meta_key, meta_value, post_date
FROM $wpdb->postmeta, $wpdb->posts
WHERE ID = post_id
AND meta_key = '$meta_key'
AND post_date BETWEEN '$start_date' AND '$end_date'
ORDER BY meta_key ASC, post_date DESC";
$results = $wpdb->get_results($sql);
foreach ($results as $row) {
echo "<p>KEY:$row->meta_key VALUE:$row->meta_value DATE:$row->post_date</p>";
}You must log in to post.