How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?

It’s informative to check out the /wp-admin/post.php file, that contains the edit_post() function that calls wp_update_post(), which is a wp_insert_post() wrapper. Here’s a skeleton for saving the assigned category terms: /** * Saving assigned category terms (skeleton) */ add_action( ‘admin_action_editpost’, function() { add_filter( ‘wp_insert_post_data’, function( $data, $parr ) { add_action( ‘save_post_post’, function( $post_ID, $post ) … Read more

How do I position meta_box on post edit screen after the title?

You cannot use a real metabox to do that, hook into edit_form_after_title instead. Here is a simple example: add_action( ‘edit_form_after_title’, ‘wpse_87478_pseudo_metabox’ ); add_action( ‘save_post’, ‘wpse_87478_save_metabox’ ); function wpse_87478_pseudo_metabox() { global $post; $key = ‘_wpse_87478’; if ( empty ( $post ) || ‘post’ !== get_post_type( $GLOBALS[‘post’] ) ) return; if ( ! $content = get_post_meta( $post->ID, … Read more

One metabox for multiple post types

Define an array of post types, and register the metabox for each one separately: function add_custom_meta_box() { $post_types = array ( ‘post’, ‘page’, ‘event’ ); foreach( $post_types as $post_type ) { add_meta_box( ‘custom_meta_box’, // $id ‘Custom Meta Box’, // $title ‘show_custom_meta_box’, // $callback $post_type, ‘normal’, // $context ‘high’ // $priority ); } }

How to reorder meta box position?

Users can drag and drop meta boxes and WordPress will save the order. So, in a sense, the order in which they were originally rendered does not matter. You know which one comes first because when you call add_meta_box it simply pushes your meta box’s args onto a global array called $wp_meta_boxes. Whichever call to … Read more