How do I add a Custom Post Type that looks and behaves exactly the same as Posts?

Creating the Post Type

register_post_type is your friend here. This is what plugins etc use to register the post type.

For example here is a basic Books post type:

function codex_custom_init() {
    $args = array(
      'public' => true,
      'label'  => 'Books'
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );

If you don’t want to write the code, there’s a site that will give you a form, answer some questions, and it will give you code at the end to copy paste, here are two such sites:

Creating the Tags and Categories

Custom taxonomies are similar, and you’ll want 2 of them for tags and categories.

register_taxonomy is the function that registers a custom taxonomy. Here’s a genre taxonomy for the book example given above:

add_action( 'init', 'create_book_tax' );

function create_book_tax() {
    register_taxonomy(
        'genre',
        'book',
        array(
            'label' => __( 'Genre' ),
            'rewrite' => array( 'slug' => 'genre' ),
            'hierarchical' => true,
        )
    );
}

Your 2 taxonomies will be the same except:

  • tags will be hierarchical, categories will not
  • they’ll have different names and labels

You’ll need to name them separately so they don’t conflict with the existing post type and taxonomies, so News Category, not Category, and News Tags, not Tags.

The sites with the easy to fill out forms also have generators for taxonomies too.

Columns in Post Listings

v3.5 added this attribute to register_taxonomy:

show_admin_column

If set to true it will add a column as you desire showing the terms of each post

Where should the code reside

Probably in a plugin, not in the theme. If they were in the theme, and the user switched themes, they’d loose all their data.

Caveats

Custom post types don’t have date archives, and adding date archives is a nontrivial, and difficult thing to do, something that is far and above beyond what your current skills are if you’re asking the question you asked. Needing date archives in a custom post type usually means you’re doing something you should have used normal posts for and have made a mistake somewhere in your design.

There will also be a post type/taxonomy prefix, you can’t give them the exact same URL structure as posts. If you did, they would clash, and either your News post type, or your standard posts would 404. ( If you did I would recommend you just use posts and you’re doing something wrong to even have a separate news post type ).

When you’ve written your code, flush your permalinks to test else the archives will give 404s.

What I Suspect You Actually Want

I suspect your next question will be how to hide Posts in the admin menu and the frontend menu. To which I present these alternative solutions:

  • Rename Posts to News without creating a whole new post type
  • Use a custom taxonomy or a category to separate news from other things.