How to create metabox that can be queried in the database?

As Kaiser suggested, the Metabox script available over at http://www.deluxeblogtips.com/2011/03/meta-box-script-update-v30.html propagates metadata to the database as individual entries instead of a serialized array. I suppose it is ultimately a matter of preference between how you want your data to be stored in the database. I have appreciated using Dimas’WP Alchemy plugin up until now, but … Read more

Change Default Custom Fields Metabox Name on cctm plugin

Try using this example from the WordPress Codex: add_action( ‘add_meta_boxes’, ‘myplugin_add_custom_box’ ); function myplugin_add_custom_box() { add_meta_box( ‘myplugin_sectionid’, __( ‘My Post Section Title’, ‘myplugin_textdomain’ ), ‘myplugin_inner_custom_box’, ‘post’ ); }

Metaboxes not saving data

There were three issues: The first wasn’t visible in the code presented. a wp_register_styles call was put into the constructor, which caused errors and somehow prevented saving post metadata. Second, the date field was a HTML5 date field, which conflisted with jQuery’s datepicker. Changing it to a text field fixed that. Third, the final if … Read more

Custom metabox with App Store / Google Play links

Ok, with the use of this ‘plugin’ (JareDatch). It works like a charm. add_filter( ‘cmb_meta_boxes’, ‘cmb_sample_metaboxes’ ); /** * Define the metabox and field configurations. ** @param array $meta_boxes * @return array */ function cmb_sample_metaboxes( array $meta_boxes ) { // Start with an underscore to hide fields from custom fields list $prefix = ‘_cmb_’; $meta_boxes[] … Read more

Remove duplicated values from meta box values

Solution I created array outside the while loop and checked if the value is in array or not. <?php $args = array(‘post_type’ => ‘posttype’); $emptyvalue = “”; $optionname = “optionname”; $the_query = new WP_Query($args); $output =”<select name=””.$optionname.””> <option value=””.$emptyvalue.””>Location</option>'”; $arr = array(); while ( $the_query->have_posts() ) : $the_query->next_post(); $id= $the_query->post->ID; $location = get_post_meta($id, ‘institution_location’, true); … Read more

why esc_url not working in smartmetabox

esc_url() is not a validator. Use PHP’s filter functions for that. Example: // $url is now an URL or FALSE $url = filter_var( ‘http://example.com’, FILTER_VALIDATE_URL ); if ( $url ) # update post meta else # delete post meta

Meta Boxes causing Header errors

It is probably here: if ( !wp_verify_nonce( $_POST[‘address_noncename’], plugin_basename(__FILE__) )) { return $post->ID; } You are using $_POST[‘address_noncename’] but aren’t checking to see if it exists before you do. That is going to trigger the warning you mentioned about an “undefined index”. If that warning prints to the screen before the headers are sent, you … Read more

Tags meta box don’t show when creating a new post type

There are essentially two ways to do this. The first is to supply the taxonomies keyword in the register_post_type arguments array, like so: register_post_type(‘my_type’, array( … ‘taxonomies’ => array(‘category’, ‘post_tag’), … )); The other is to register your post type and set up its taxonomies at a later point: register_taxonomy_for_object_type( ‘category’, ‘my_type’ ); register_taxonomy_for_object_type( ‘post_tag’, … Read more

Option to delete value in metabox

Use delete_post_meta to delete a value. Example: delete_post_meta($post->ID, ‘brk_news_update’); If you want to update it, then use update_post_meta update_post_meta($post->ID, ‘brk_news_update’,’value’);