Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I had created a custom meta box with the help of this answer but this meta box only appear in Post edit screen. How I can make it visible on "Pages" as well as on custom post types which created by my current theme.

Update: The code is from function.php which add Custom Meta Box:

    /* Define the custom box */
add_action( 'add_meta_boxes', 'wpse_61041_add_custom_box' );

/* Do something with the data entered */
add_action( 'save_post', 'wpse_61041_save_postdata' );

/* Adds a box to the main column on the Post and Page edit screens */
function wpse_61041_add_custom_box() {
    add_meta_box( 
        'wpse_61041_sectionid',
        'Does this page is in Englsih?',
        'wpse_61041_inner_custom_box',
        'post',
        'side',
        'high'
    );
}

I do not understand how to add page & custom-post-types to make that meta-box visible there.

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

You can do something like this:

function wpse_61041_add_custom_box() {
        //Place your custom post types in the array
        $post_types = array ( 'post', 'page', 'another_custom_post_type' );

        //Then loop through all post types and add meta boxes to them
        foreach( $post_types as $post_type )
        {
           add_meta_box( 
             'wpse_61041_sectionid',
             'Does this page is in Englsih?',
             'wpse_61041_inner_custom_box',
             $post_type,
             'side',
             'high'
           );
        }
}
share|improve this answer
    
Thank you, solved by adding $post_types = array ( 'post', 'page' ); –  John Doe Oct 9 '13 at 9:22
add comment

If we look at the add_meta_box() function, wee see that it takes the following structure:

<?php
   add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );
?>

Based on the tutorial you linked, "post" is the post type, which is why the box only shows up there. Perhaps you will find it less troublesome to generate your meta box content with ACF then export the PHP to your theme?

The manual solution is here (amabil's solution).

share|improve this answer
    
Thanks, but code add meta-box in different way & I am new to PHP. –  John Doe Oct 9 '13 at 8:16
add comment

I always use Meta Box API, it is very easy:

Multiple post meta example:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.