How to store post meta in an array

WordPress automatically serializes/unserializes the data when it’s stored and retrieved, all you need to do is pass a php array as your data and you’ll get the same array back when you get_post_meta. $data = array( ‘label’ => ‘something’, ‘desc’ => ‘someval’, ‘id’ => ‘someval’, ‘type’ => ‘someval’ ); update_post_meta( $post_id, ‘your_key’, $data ); $data … Read more

Correct syntax for retrieving custom field in CPT

If you have the CPT’s ID in the $event_id variable you plug into the get_post() call – why would you not simply just (re)use that for the first parameter of get_post_meta() ? That aside, get_post() returns a post object (instance of WP_Post), which you choose to assign to $event. Hence $event now has a public … Read more

Saving zero in meta box

Your issue seems to be with too loose logic check, rather than saving. To treat valid but falsy value correctly you need something like this: if ( false !== $meta_value ) This will strictly match only the case when value doesn’t contain false (return of the API when fetch failed).

meta fields for the whole wordpress site

You are talking about “Options”. These are saved in the *_options table and can be stored and retrieved using a number of Core functions (straight from the Codex page above): Add/Delete Option add_option() delete_option() add_site_option() delete_site_option() Get/Update Option get_option() update_option() get_site_option() update_site_option()

WP Query – Is this correct?

I am guessing but based on your choice of placeholder names in the code above… $args = array( ‘meta_key’ => ‘myvalue’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ ); … your meta_key argument is wrong. That is the meta key not the meta value as your naming convention suggests. meta_key (string) – Custom field key. http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters … Read more