add_post_meta() & update_post_meta()

add_post_meta() : Adds a meta field to the given post. Below is the example, <?php $post_id = 1; $meta_key = ‘_test’; $meta_value=”this is a test”; $unique = true; add_post_meta( $post_id, $meta_key, $meta_value, $unique ); update_post_meta() : if the given key already exists among custom fields of the specified post, another custom field with the same … Read more

Output from Meta Box Array

Add meta data as “flat” data to the post The actual problem is, that your meta data comes back as array (with a single entry), when calling get_post_custom( $id ); for your post. Here’s a simple function, that adds all meta data attached to a post to your post object. /** * Merges custom/meta data … Read more

Add a meta box to ALL Pages

Try this. This is part of some code I use. // Add meta boxes to Page add_meta_box( ‘RelatedImage’, __(‘Related images’), ‘related_images_meta_box’, ‘page’, ‘normal’, ‘high’ ); function related_images_meta_box($object) { $nonce = wp_create_nonce(plugin_basename( __FILE__ )); ?> <input type=”hidden” name=”wp_filebrowser_nonce” id=”wp_filebrowser_nonce” value=”<?php echo $nonce; ?>” /> <table> <tr> <td> <label for=”related_image” class=””>Related image</label> </td> <td> <input type=”text” id=”related_image” … Read more

Polylang not translating Metabox fields [closed]

Turn off custom fields syncronisation on polylang. I would also then add specific code to tell polylang to copy (not sync) the metas upon translation creation (so when you click ‘+’ it will also copy the metas, but changing the metas after this, won’t sync with other translations): add_filter(‘pll_copy_post_metas’, ‘copy_post_metas’, 10, 2); function copy_post_metas($metas, $sync){ … Read more

Save meta value as an array of arrays

If you don’t need to query on the data, you can pass arrays directly to the post meta functions, WordPress will automatically serialize/unserialize the data for you. $your_array = array( array( ‘title’ => ‘something’, ‘price’ => ‘something’, ), array( ‘title’ => ‘something’, ‘price’ => ‘something’, ), ); update_post_meta( $post_id, ‘your_key’, $your_array );

List all sidebars in metabox

The class you are using accepts value => name pair in the select options array so foreach ( $GLOBALS[‘wp_registered_sidebars’] as $sidebar ) { $sidebar_options[$sidebar[‘id’]] = $sidebar[‘name’]; } and then you can use $sidebar_options.