Create custom PAGE with register_post_type

The following code in functions.php outputs a post when I publish, not a Page:

// custom post_type for agenda
add_action( 'init', 'create_my_post_types' );    
function create_my_post_types() {
    register_post_type( 'agenda', array(
        'labels' => array(
            'name_admin_bar' => _x( 'Agenda', 'add new on admin bar' ),
        ),
        'public' => true,
        'publicly_queryable' => false,
        'capability_type' => 'page',
        'map_meta_cap' => true,
        'hierarchical' => true,
        'rewrite' => false,
        'query_var' => false,
        'delete_with_user' => true,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
    ) );}

What am I doing wrong?

Read More

The full problem:

I need to add a metabox to a page, but only the “agenda” page, I don’t want this metabox to appear in every page in admin panel, so I’m creating a custom post_type with the exact same functions of a page, only with a different post_type to be able to set a metabox to it alone.

Screenshot of current output:

http://i.stack.imgur.com/oPEx8.png
(can’t post direct images yet, so please click link)

Related posts

Leave a Reply

2 comments

  1. Your screenshot seems to indicate that you’re interested in the status message for your custom post type saying 'Page updated. View page'. If that’s true, the reason that you’re getting 'Post updated. View post' is that you haven’t provided status messages for your custom post type.

    Here’s the code for the admin edit page (edit-form-advanced.php):

    if ( isset($_GET['message']) ) {
        $_GET['message'] = absint( $_GET['message'] );
        if ( isset($messages[$post_type][$_GET['message']]) )
            $message = $messages[$post_type][$_GET['message']];
        elseif ( !isset($messages[$post_type]) && isset($messages['post'][$_GET['message']]) )
            $message = $messages['post'][$_GET['message']];
    }
    

    So the edit screen is trying to retrieve messages for your $post_type (agenda), not finding them, and displaying the post messages.

    You can fix this by creating $messages['agenda'] with something like the approach described on the Register Post Type function reference:

    function agenda_update_messages( $messages ) {
      global $post, $post_ID;
      $messages['agenda'] = array(
        // ...
        1 => sprintf( __('Page updated. <a href="%s">View page</a>', 'your_text_domain'),
                      esc_url( get_permalink($post_ID) ) ),
        // ...
      ); 
      return $messages;
    }
    add_filter( 'post_updated_messages', 'agenda_update_messages' );
    
  2. You Don’t need to create a custom post type just add the metabox if the page is the one you require ex:

    add_action('admin_init','meta_on_agenda_only');
    
    function meta_on_agenda_only(){
        $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    
        // checks for post/page ID change the 00 to the ID pf your agenda page
        if ($post_id == '00' || is_page('agenda'))  {
            //add your metabox
            add_meta_box('meta_box_id', 'Meta Box name', 'callback_function', 'page', 'normal', 'high');
        }
        //hook the save action
        add_action('save_post','my_meta_save');
    
    }