• 22 Comments
    1. Vince Kurzawa

      In your last screenshot I noticed your “Excerpt” box has been renamed to “Gallery Description.” I’ve been looking all over Google and can’t find a way to do this.
      Would you let me know, or point me in the right direction of how to do this?

      12:23 am on March 8th, 2011 Reply
      • That is actually a custom metabox that I added with -
        add_meta_box( ‘post-content-div’, __(‘Gallery Description’), ‘gallery_description_metabox’, ‘gallery’, ‘normal’, ‘high’);

        4:44 pm on March 9th, 2011 Reply
        • Vince Kurzawa

          Oh cool. Thanks for the code snippet, it helps a bunch. There is just so much to learn about the WordPress API!

          6:03 pm on March 12th, 2011 Reply
    2. Ups! Sorry, delete my earlier post. Forgot to write my question.
      Cant get the code to work, have tried everything. Can you se whats wrong?

      4:38 pm on February 10th, 2011 Reply
      • Your posted code didn’t come through properly. Try encapsulating your code in <pre> tags, or use pastebin.

        9:13 am on February 12th, 2011 Reply
    3. jamie

      this would have been a great tut had you not left out the part about retrieving the information from the database. How do I get the values from the radio buttons?

      5:37 pm on February 2nd, 2011 Reply
      • I am not sure I understand your question.

        In the save_gallery_data function, values from the radio buttons ($_POST['gallery_type']) are retrieved and stored (line 22).

        2:58 pm on February 3rd, 2011 Reply
    4. I’ve made a blank example for custom meta boxes on posts, and give explanation on how to insert them into custom post types as well here. I’d love to know what you think.

      4:50 am on January 30th, 2011 Reply
    5. sebouille

      Hi
      How i can restrict meta box category with arg child-of ?

      I created a plugin with
      add_action(‘load-post.php’, array(‘Myplugin’,'loadpost’));
      And
      function loadpost() {
      remove_meta_box(‘categorydiv’, ‘post’, ‘normal’);
      add_meta_box(‘categorydiv’, _(‘Category’), ‘post_categories_meta_box’, ‘post’, ‘side’, ‘core’, array( ‘taxonomy’ => ‘category’, ‘child_of’ => 80));
      }
      Have any idea ?
      Thanks for great blog

      1:22 am on October 25th, 2010 Reply
      • sebouille

        I find with this function
        wp_terms_checklist($post->ID, array( ‘taxonomy’ => $taxonomy, ‘descendants_and_self’ => $wp_cat_id_mother, ‘selected_cats’ => $idCatSelected ) )
        So
        1) remove_meta_box(‘categorydiv’, ‘post’, ‘normal’);
        2) add_meta_box(‘categorydiv1′, _(‘Categories’), array( ‘MyPluginClass’, ‘display_restrict_category’), ‘post’, ‘side’, ‘core’);
        3)
        function display_restrict_category( ) {

        wp_terms_checklist($post->ID, array( ‘taxonomy’ => $taxonomy, ‘descendants_and_self’ => $wp_cat_id_mother, ‘selected_cats’ => $idCatSelected ) )

        }

        Thanks

        4:10 am on October 26th, 2010 Reply
    6. Here’s a good plugin that handles all the custom metaboxes for you as well as custom post types. http://wordpress.org/extend/plugins/custom-metaboxes/

      10:06 pm on August 27th, 2010 Reply
    7. Alex

      SOLVED IT !!!

      Its necesary to add this action

      add_action(‘admin_menu’, ‘architecture_admin_menu’);

      4:33 pm on July 6th, 2010 Reply
      • Where do you add the action? beginning or end of the code?

        Would be great to see the code in full!

        -J

        9:11 am on July 13th, 2010 Reply
        • I usually add the admin_menu hook at the beginning of my theme functions.php file or at the beginning of my main plugin file. I put it together with the init and admin_init hooks. When I use class wrappers, I put it within the class constructor function. If you want to look at an example plugin with these function calls then check out the Shiba Example plugin.

          The register_post_type function call I execute from my init function.

          Both the Shiba Media Library plugin and Shiba Custom Background plugin use custom post type metaboxes. Full working code can be found there but the plugins also contain a whole bunch of other stuff.

          9:16 pm on July 13th, 2010 Reply
    8. Alex

      Ey men! your last posts about custom post types are amazing!! I just created my first custom type, but when trying to add a meta box gives me this error.

      Fatal error: Call to undefined function add_meta_box() in /home/xxx/public_html/wp-content/themes/xxx/custom-types.php on line 43

      custom-types is an include in functions.php

      I am using wordpress 3.0

      This is the code in custom-types.php

      	$labels = array(
      		'name' =&gt; _x('Architecture', 'post type general name'),
      		'singular_name' =&gt; _x('Architecture', 'post type singular name'),
      		'add_new' =&gt; _x('Add New', 'work'),
      		'add_new_item' =&gt; __("Add New work"),
      		'edit_item' =&gt; __("Edit work"),
      		'new_item' =&gt; __("New work"),
      		'view_item' =&gt; __("View work"),
      		'search_items' =&gt; __("Search Works"),
      		'not_found' =&gt;  __('No work found'),
      		'not_found_in_trash' =&gt; __('No work found in Trash'), 
      		'parent_item_colon' =&gt; ''
      	  );
      	  $args = array(
      		'labels' =&gt; $labels,
      		'public' =&gt; true,
      		'publicly_queryable' =&gt; true,
      		'show_ui' =&gt; true, 
      		'query_var' =&gt; true,
      		'rewrite' =&gt; true,
      		'capability_type' =&gt; 'post',
      		'hierarchical' =&gt; false,
      		'menu_position' =&gt; null,
      		'supports' =&gt; array('title','editor')
      	  ); 
      	  register_post_type('architecture',$args);
       
      	  function architecture_type_metabox($post) {
       
      	}
       
      	add_meta_box('architecture-type-div', __('Datos tecnicos'),  'architecture_type_metabox', 'architecture', 'normal', 'low');

      Please! help, wp is correctly updated to 3.0, i can find the function add_meta_box and cant find why this happens!

      ++Thanks++

      4:14 pm on July 6th, 2010 Reply
      • Andrew

        FYI, this part is not “out of the box” so you have to wrap it into a function and use add_action such as


        add_action( 'admin_init', 'news_meta_boxes', 1 );

        // Add meta box goes into our admin_init function
        function news_meta_boxes() {
        add_meta_box('gallery-type-div', __('Gallery Type'), 'gallery_type_metabox', 'news', 'normal', 'high');
        }

        This also lets you add all your meta boxes in one add_action as referenced in the codex at http://codex.wordpress.org/Function_Reference/add_meta_box

        8:13 am on September 9th, 2011 Reply
    9. Thanks very much, i’ve been searching for how to do meta box stuff on the new custom post types and this article has finally helped me to understand.

      3:17 am on June 29th, 2010 Reply
    10. Thanks for this, very useful!

      I created a checkbox to flag featured “Best Practices” on a site I am putting together. Perhaps this will be helpful to your readers:

      add_action('admin_menu', 'featured_add_custom_box');
      add_action('save_post', 'featured_save_postdata');
       
      /* Adds a custom section to the "advanced" Best Practices */
      function featured_add_custom_box() {
      	add_meta_box( 'featured_sectionid', __( 'Featured', 'featured_textdomain' ), 'featured_inner_custom_box', 'bestpractices', 'advanced' );
      }
       
      /* Prints the inner fields for the custom post/page section */
      function featured_inner_custom_box( $post ) {
       
      	$featured = get_post_meta($post-&gt;ID, '_featured', true);
      	if ($featured == 1) $checked = 'checked="checked"'; else $checked = '';
       
        echo 'ID) . '" /&gt;';
        echo '' . __("Featured?", 'featured_textdomain' ) . ' ';
        echo '';
      }
       
      /* When the post is saved, saves our custom data */
      function featured_save_postdata( $post_id ) {
       
      	if ( !wp_verify_nonce( $_POST['featured_noncename'], 'featured'.$post_id ))
      		return $post_id;
       
        if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) 
          return $post_id;
       
        if ( !current_user_can( 'edit_page', $post_id ) )
          return $post_id;
       
      	$post = get_post($post_id);
      	if ($post-&gt;post_type == 'bestpractices') {
      		if(esc_attr($_POST['featured'] == "on")) $val = 1; else $val = 0;
      		update_post_meta($post_id, '_featured', $val );
      		return(esc_attr($_POST['featured']));
      	}
      }
      10:08 am on June 28th, 2010 Reply
      • Examples like these are always very useful. Thanks for sharing it with us Darren.

        2:27 pm on June 28th, 2010 Reply
    11. [...] Read the rest here: Add a Metabox to Your Custom Post Type Screen [...]

      4:34 pm on June 25th, 2010 Reply
    12. Matt

      Oh, my gosh, thank you thank you thank you. I have been dealing with this stupid nonce thing looking for help. I stumbled onto your site and this method works great. Thank you so much!

      7:11 pm on June 21st, 2010 Reply

    Leave a Reply

    Your email address will not be published.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

    search button search button
    rss