How did you pass the array to the custom field? did you serialize the array or do you have a custom field “data” with a “date” value?
Hi keesiemeijer –
-> I stored the date in the array: $data[‘my_date’]= “02/12/2010”;
(the array $data contains all the different pieces of information that I need to access here and there and there are a lot of them so I thought it would be more practical to store them all in one single array variable))
-> then I create a post with
wp_insert_post( $my_post );
-> and then I use
add_post_meta($myinsertedpostID, ‘data’, $data);
(Unfortunately, having the date stored as a string was enough until now so that’s what I did :/)
the array $data contains all the different pieces of information that I need to access here and there and there are a lot of them so I thought it would be more practical to store them all in one single array variable
This isn’t more practical because now you can’t query them individually.
add_post_meta serializes the array anyway.
I tried this and it pulled out the right post (ID 834):
$data = array('my_date' => '02/12/2010', 'color' => 'blue');
add_post_meta(834, 'data', $data);
$query = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'data' AND meta_value LIKE '%my_date%' AND meta_value LIKE '%02/12/2010%'";
$results = $wpdb->get_results($query);
// for testing
echo '<pre>';
print_r($results );
echo '</pre>';