How do I save metadata for a specific custom post type only?

function save_my_metadata($ID = false, $post = false) { if($post->post_type != ‘your_post_type’) return; update_post_meta($ID, ‘my_metadata’, $_POST[‘my_metadata’]); } That should work. Just replace ‘your_post_type’ with the name of the post type. Also, little known fact: the ‘save_post’ hook passes the post’s ID as an argument. EDIT I updated the function to reflect Jan’s comment. Thanks Jan!

Custom bulk_action

I think the latest major release warrants a new answer to this question, considering the popularity of this question. Since WordPress 4.7 (released December 2016) it is possible to add custom bulk actions without using JavaScript. The filter bulk_actions-{$screen} (e.g. bulk_actions-edit-page for the pages overview) now allows you to add custom bulk actions. Furthermore, a … Read more

Theme localization of “slugs” (custom post types, taxonomies)

I wouldn’t try to localize your slugs. Instead, why not give your users the option to change them by adding another field to the permalink settings page? Hook into load-options-permalink.php and set up some things to catch the $_POST data to save your slug. Also add a settings field to the page. <?php add_action( ‘load-options-permalink.php’, … Read more

How to change default position of WP meta boxes?

You can remove the default meta boxes with remove_meta_box and re-add them in a different position with add_meta_box: add_action(‘do_meta_boxes’, ‘wpse33063_move_meta_box’); function wpse33063_move_meta_box(){ remove_meta_box( ‘postimagediv’, ‘post’, ‘side’ ); add_meta_box(‘postimagediv’, __(‘Featured Image’), ‘post_thumbnail_meta_box’, ‘post’, ‘normal’, ‘high’); } This will remove it from the side column and add it to the main column. change post in this example … Read more

New post status for custom post type

There is a great Step by Step description on how to do that here https://www.jclabs.co.uk/create-custom-post-status-in-wordpress-using-register_post_status/ To add your custom post status to the drop-down menue, just add the following to your themes function script: add_action(‘admin_footer-post.php’, ‘jc_append_post_status_list’); function jc_append_post_status_list(){ global $post; $complete=””; $label=””; if($post->post_type == ‘recipes’){ if($post->post_status == ‘aggregated’){ $complete=” selected=\”selected\””; $label=”<span id=\”post-status-display\”> Aggregated</span>”; } echo … Read more

Creating an Image-Centric Custom Post Type?

goldenapple’s initial answer gave me the jumpstart I needed to finish this up. functions.php Here is the complete code I’m using to add a new post type “header-image” and modify other admin screens accordingly: /** * Register the Header Image custom post type. */ function sixohthree_init() { $labels = array( ‘name’ => ‘Header Images’, ‘singular_name’ … Read more