Post.php – Conditional statements for new post and edit post

edit.php is the post/page list, the post creation/editing screen are 2 separate files: post-new.php and post.php. so you can target using “load-$page” hook, e.g.: add_action( ‘load-post.php’, function() { // add metabox or whatever you want when EDITING post add_action( ‘add_meta_boxes’, ‘myplugin_meta_box_editing’ ); } ); add_action( ‘load-post-new.php’, function() { // add metabox or whatever you want … Read more

Adding Metaboxes – so much code is there a shorter DRY way?

Leverage Functions You can extract the redundant code into reusable functions. For example, the last two functions could be rewritten like this. My resulting code is actually 2 lines longer, but it’s much cleaner from a debugging standpoint. And, if there were a third custom field, this approach would definitely be shorter. function slidestoshow_save_post_meta_box( $post_id, … Read more

MetaBox Layout for all users

You could setup a different default layout by hooking into do_meta_boxes, take a look here: How to change default position of WP meta boxes? Or you could use the global variable $wp_meta_boxes to do so: Get List of Registered Meta Boxes and Removing Them How to Remove Certain Screen Options and Meta Boxes from add/edit … Read more

Why is save_post hook not running?

Try this in your theme’s functions.php file, or a .php file of a plugin that you may be writing: add_action(‘save_post’, ‘xxx_save_meta_box’); function xxx_meta_box_callback() { add_meta_box(‘xxx-meta’,’xxx Details’,’xxx_meta_box’,’xxx-post-type’,’side’,’default’); error_log(‘meta box cb’); } function xxx_save_meta_box($post_id, $post) { error_log(‘running …’); die(‘OK!!!’); }

WordPress media manager multiple selection output

It was just my mistake… I’ve forgotten improve var selection jQuery(document).ready(function($){ var custom_uploader; $(‘#upload_image_button’).click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen the dialog if (custom_uploader) { custom_uploader.open(); return; } //Extend the wp.media object custom_uploader = wp.media.frames.file_frame = wp.media({ title: ‘Choose Image’, button: { text: ‘Choose Image’ }, multiple: true }); custom_uploader.on(‘select’, … Read more