WordPress.org

Ready to get started?Download WordPress

Forums

Need to clarify the usage of add_meta_box in WordPress (6 posts)

  1. spstieng
    Member
    Posted 3 years ago #

    I have the follwoing code:

    function create_custom_meta_box() {
          add_meta_box( 'Intro', __('Intro'), 'post_intro_meta_box', 'post', 'normal', 'high' );
          add_meta_box( 'Intro', __('Intro'), 'post_intro_meta_box', 'page', 'normal', 'high' );
          add_meta_box( 'RelatedImage', __('Related images'), 'related_images_meta_box', 'post', 'normal', 'high' );
          add_meta_box( 'RelatedImage', __('Related images'), 'related_images_meta_box', 'page', 'normal', 'high' );
          add_meta_box( 'GuestAuthor', __('Guest Author'), 'author_meta_box', 'post', 'normal', 'low' );
        }

    As you can see, I'm using 'Intro' and 'RelatedImage' twice. Is this wrong? Do they have to be unique?

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    Should be fine since you're adding them to different post types.

    The example shown here uses the same meta box twice (for different post types).
    http://codex.wordpress.org/Function_Reference/add_meta_box

    Are you having problems with the code?

  3. spstieng
    Member
    Posted 3 years ago #

    Yeah.

    It all worked fine until yesterday. Now it's rather unstable. Sometimes it all works, then only data in Related images meta box is saved.

    Even when removing most of my stuff in functions.php and only add one metabox, data is not saved.

    Would be really nice to be able to debug this somehow.

  4. spstieng
    Member
    Posted 3 years ago #

  5. Mark / t31os
    Moderator
    Posted 3 years ago #

    The two URLs suggested by Michael here give very good examples and still relevant.
    http://wordpress.org/support/topic/adding-plugins-meta-boxs-to-custom-post-types

    I've not personally worked with adding custom meta boxes, so i'm not really aware of any common problems, i can only suggest following other similar threads and/or tutorials focused on using meta boxes with custom post types.

    I'd assume you already followed an existing example, but if you're having problems with the code i'm not sure what to suggest other than perhaps trying a different method.

  6. spstieng
    Member
    Posted 3 years ago #

    Thanks, will check it out.
    Yeah. Looked at examplse here, at WP Engineer and some other tutorials.

Topic Closed

This topic has been closed to new replies.

About this Topic