mardi 24 février 2015

Custom Post Type meta value is being saved in array, instead of just the string (as value)


So, this is how WordPress is saving my CPT meta:



array(8) {
["product_id"]=> array(1) { [0]=> string(10) "abcdefg987" }
["end_date"]=> array(1) { [0]=> string(10) "02-02-2015" }
}


But I want it to be like this:



array(8) {
["product_id"]=> "abcdefg987" ,
["end_date"]=> "02-02-2015"
}


So, is it possible ?




Here is some of my code:

to save:

update_post_meta($post_id, "end_date", $_POST["end_date"]);

The meta box:



global $post;
$custom = get_post_custom($post->ID);
$end_date = $custom["end_date"][0]; // <- this was an old hack to this problem
<p><label>End Date:</label><br />
<input name="end_date" value="<?php echo $end_date; ?>"></input></p>




What I really want to do ?

What I need is to get the Post (custom) with the 'end_date' greater than today. So, I have a meta_query, but doesn't work, cause also shows me the posts with 'end_date' < today, so I thought is because it get its values in the array, and not just the values, here is the code:



$args = array(
'post_type' => 'myEventCPT',
'meta_query' => array(
array( 'meta_key' => 'end_date',
'value' => date("m-d-Y"), // Set today's date
'compare' => '>=',
//'type' => 'DATE'
)
)
);
$my_event_post = get_posts( $args );




Aucun commentaire:

Enregistrer un commentaire