Question

I want to save multiple dates in meta key.

I have a three dates 2,3,4 and I want to save all these values in same meta key but as a different values.

For example:

dates(meta key) 2(meta value)
dates(meta key) 3(meta value)
dates(meta key) 4(meta value)
Was it helpful?

Solution

This should work out of the box, as long as the "unique" parameter of add_post_meta() is false.

add_post_meta($id, '_dates', 2, false);
add_post_meta($id, '_dates', 3, false);
add_post_meta($id, '_dates', 4, false);

then somewhere else

$dates = get_post_meta($id, '_dates', false);

Now $dates should be an array of your 3 values.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top