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.

Display Content if Meta Checkbox is checked?

First make the custom post query with the WP_Query, and then we get the metadata by get_post_meta. Checkboxses are saved as boolean, that means either true or false. So make a check in the loop if checked or not (1=true, 0=false). <?php get_header(); ?> <?php // The Query $the_query = new WP_Query( array( ‘post_type’ => … Read more