- 25+ Projects Delivered • 5 Years Experience • UK, USA & Pakistan Clients • Free SEO Audits - 25+ Projects Delivered • 5 Years Experience • UK, USA & Pakistan Clients • Free SEO Audits 

- 25+ Projects Delivered • 5 Years Experience • UK, USA & Pakistan Clients • Free SEO Audits - 25+ Projects Delivered • 5 Years Experience • UK, USA & Pakistan Clients • Free SEO Audits 

Back issues Writing

Custom Post Types Without a Plugin: The Whole File

Two live installs carry 14 plugin post types and 8 published entries between them. The reviews section you want is 92 lines of PHP.

Topics

I opened /wp-json/wp/v2/types on the two WordPress sites I look after. One answered with 20 post types, the other with 16, and 14 of those came from plugins rather than from WordPress.

Then I asked each type for its published entry count. Of the 12 that answer without a login, 8 hold none, and the 4 that hold anything hold 8 entries between them. Not one of the 14 declares an archive.

That is a plugin-registered type from the outside: storage for a template, a modal or a map, drawn somewhere you did not ask about. A reviews section is a different job.

Short answer

A review or project section is one function on init calling register_post_type with a labels array, a rewrite slug and an archive, plus one rewrite flush on activation. Put it in a small plugin or an mu-plugin rather than the theme, use capability_type => 'post' unless you intend to grant a capability nobody holds, and flush on the event where the type is already registered.

Two kinds of claim sit here. Argument names, defaults and hook order are read from the code reference and the plugin handbook, with the page linked under each. The counts are measured: blog-pipeline/tools/measure_cpt.py read the type list off both installs and downloaded the plugin zip into blog-pipeline/data/cpt_census.json, and the post formats from it.

None of it was executed: there is no PHP binary on this machine, so nothing below ran on a WordPress install. The behaviour is documented, the counts are measured, and the file is 92 lines you can read.

What the two installs already carry

The REST types endpoint lists every post type a site exposes, with the rest_base that serves its entries. One request per type with per_page=1 returns an X-WP-Total header carrying the count. Here is everything that is not core, so the total adds up:

TypeInstallPublished entries
e-floating-buttonsprovidarcm.com0
elementor_libraryprovidarcm.com-
elementor_snippetprovidarcm.com3
elementskit_contentprovidarcm.com1
elementskit_templateprovidarcm.com0
ocean_modal_windowprovidarcm.com0
igmapprovidarcm.com1
oceanwp_libraryprovidarcm.com0
rm_content_editorprovidarcm.com0
elementor_librarymedfactorinc.com-
elementor_snippetmedfactorinc.com0
elementskit_contentmedfactorinc.com3
elementskit_templatemedfactorinc.com0
rm_content_editormedfactorinc.com0

A dash means the endpoint answered 401 and that count needs a login. Two installs, 20 and 16 types, 14 from plugins, 8 published entries in total, and no archive on any of them.

Elementor keeps templates and custom code in two of those types, ElementsKit its blocks, OceanWP its modals, a map plugin its maps. None is a section a visitor browses. Each is a drawer the plugin opens for itself, because the post table and the editor are cheaper than building storage.

A type with no archive has no public listing. Right for a template library, wrong for the reviews page you want.

The plugin you were about to install

The obvious move is a plugin that registers types from a settings screen. Custom Post Type UI sits at 1,000,000 active installs in the directory, a bucket rather than an exact number. Version 1.19.3 unpacks to 19 PHP files and 11,303 lines of PHP, 559 of them in the two files of its bundled external directory, plus 4 JavaScript files.

CPT UITHIS FILEPHP files191Lines of PHP11,30392Screens for typesincludednoneUpdateseach releasenone
PHP FILESCPT UI: 19This file: 1LINES OF PHPCPT UI: 11,303This file: 92SCREENS FOR TYPESCPT UI: includedThis file: noneUPDATESCPT UI: each releaseThis file: none
Every line in every .php file, bundled code included: the Custom Post Type UI 1.19.3 zip and blog-pipeline/data/register-review-type.php, counted by tools/measure_cpt.py on 2026-11-20.

This is not a complaint about that plugin: it gives you a screen for creating types and taxonomies, and if you register one a month it earns its place. For one type on one site, though, you add a plugin of 11,303 lines that loads on every request, and a dependency on someone else’s release schedule, to avoid writing 92 lines once.

Two rows are judgement, not measurement: “Screens for types” and “Updates” are my reading of what each route asks. The counts come from the zip.

The call, argument by argument

The call fits on one screen:

register_post_type(
	'rshn_review',
	array(
		'labels'       => array(
			'name'          => __( 'Reviews', 'rshn' ),
			'singular_name' => __( 'Review', 'rshn' ),
		),
		'public'       => true,
		'has_archive'  => true,
		'rewrite'      => array( 'slug' => 'reviews', 'with_front' => false ),
		'supports'     => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ),
		'show_in_rest' => true,
	)
);

Six arguments carry the behaviour. public is shorthand: setting it true implies exclude_from_search: false, publicly_queryable: true, show_in_nav_menus: true and show_ui: true, and each can be overridden alone. has_archive is false by default, so the type gets single pages and no listing until you say otherwise. rewrite defaults to true with the identifier as the slug, which is how the handbook’s product lands at /wporg_product/wporg-is-awesome/ until you set one.

show_in_rest is the one people forget. The reference says it must be true for the type to be available in the block editor. Without it you get the classic editor, no REST route, and no line in the types endpoint I used at the top.

The identifier has a hard limit. The function rejects an empty name or one over 20 characters with “Post type names must be between 1 and 20 characters in length”, because the post_type column is that long. The handbook adds two rules: prefix it with something of yours, and never start it with wp_. Prefixing looks fussy until two plugins pick the same identifier, which then cannot be resolved without disabling one.

Skip the labels array and WordPress does not invent your noun. The reference says post labels are inherited for non-hierarchical types and page labels for hierarchical ones, so your Reviews menu reads Posts, with “Add New Post” at the top of the editor. Five keys carry the weight: name, singular_name, menu_name, add_new_item, search_items.

Capabilities are where a menu disappears. capability_type is the base WordPress builds read, edit and delete capabilities from, and the reference lists what it constructs: edit_posts becomes edit_{capability_type}s, and the same pattern makes publish_{capability_type}s, delete_others_{capability_type}s and eleven more. With capability_type => 'post' anyone who edits posts edits reviews. Set it to review and the type checks edit_reviews and the rest, which no role holds, so the menu hides from every role until you grant them yourself. For one section on a site you own, 'post' is the honest setting.

The rewrite trap that 404s a new archive

Register a type with an archive and the page is not there. Rewrite rules are stored, not derived per request, so the site serves the set it built before your type existed. The reference says that without a flush you open Settings, then Permalinks and save before the archive answers.

The fix is one call on one event. The reference and the activation hooks chapter both say to register the type and then flush, inside the activation callback:

function rshn_activate() {
	rshn_register_sector_taxonomy();
	rshn_register_review_type();
	flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'rshn_activate' );

function rshn_deactivate() {
	unregister_taxonomy( 'rshn_sector' );
	unregister_post_type( 'rshn_review' );
	flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'rshn_deactivate' );

The flush writes whatever is registered when it runs. If the activation callback fires before the class that registers the type is loaded, you write rules without your type and the archive stays 404. That is the note contributors keep adding under flush_rewrite_rules(). Call the registration function yourself, inside the callback, before you flush.

The deactivation callback unregisters first, because a flush on deactivation without unregistering writes back the rules you were removing.

The call is expensive. The reference says so, and adds that the default hard flush rewrites .htaccess. Never put it on init or a page load. A theme gets after_switch_theme instead.

The install order, and the check:

01Register on initNever on load, never earlier02Set the URL in rewriteSlug, not the identifier03Flush on activationRegister first, then flush04Open the archive404 means rules are stale05Column, exact typeManage hook, full slug06Confirm in REST/wp-json/wp/v2/types
01Register on initNever on load, never earlier02Set the URL in rewriteSlug, not the identifier03Flush on activationRegister first, then flush04Open the archive404 means rules are stale05Column, exact typeManage hook, full slug06Confirm in REST/wp-json/wp/v2/types
The order I install a content type in. Step 6 is the check run in the last section; steps 1 to 5 are read from the code reference.

Where the file lives

A normal plugin is what the handbook recommends: “We recommend that you put custom post types in a plugin rather than a theme. This ensures that user content remains portable even if the theme is changed.” Register the type in functions.php and the day you switch themes the content is still in the database with nothing left to read it.

An mu-plugin is one file in wp-content/mu-plugins with the same header. The advanced administration handbook says these are enabled automatically, do not show in the normal plugin list, and cannot be disabled from wp-admin. Its “when not to use” list has the item that matters: plugins that depend on activation hooks.

A file that is active from the moment it lands never fires register_activation_hook, so the flush never runs and the archive 404s with the type correctly registered. In an mu-plugin, save an option and flush on the next init when the option is missing, or open Settings, then Permalinks and save once by hand, which is what I do on a site only I maintain.

A child theme is the third option, and the one I avoid for a content type.

Columns, and the order the list comes back in

A reviews list with no rating column is a list of titles. The columns filter is documented for posts, and the same page names the per-type pair: manage_{$post_type}_posts_columns for the headings and manage_{$post_type}_posts_custom_column for a cell. Both are literal in core with the type substituted, which I checked in WP_Posts_List_Table before writing this.

add_filter( 'manage_rshn_review_posts_columns', 'rshn_review_columns' );

function rshn_review_column_cell( $column, $post_id ) {
	if ( 'rshn_rating' === $column ) {
		$rating = get_post_meta( $post_id, 'rshn_rating', true );
		echo $rating ? esc_html( $rating . ' / 5' ) : '-';
	}
}
add_action( 'manage_rshn_review_posts_custom_column', 'rshn_review_column_cell', 10, 2 );

The hook name takes the full identifier, not the rewrite slug. rshn_review works and reviews renders nothing, with no error to say why. That is the most common reason a column does not appear.

Ordering is a separate hook. pre_get_posts runs on every query, including the ones in your sidebar, so the reference says to guard it with is_admin() and $query->is_main_query().

function rshn_review_admin_order( $query ) {
	if ( ! is_admin() || ! $query->is_main_query() ) {
		return;
	}
	if ( 'rshn_review' !== $query->get( 'post_type' ) ) {
		return;
	}
	$query->set( 'meta_key', 'rshn_rating' );
	$query->set( 'orderby', 'meta_value_num' );
}
add_action( 'pre_get_posts', 'rshn_review_admin_order' );

One warning. A review with no rating has no meta row, and a meta_key order becomes an EXISTS clause that the meta query source builds with an inner join, so those reviews drop out of the list rather than sorting last. If that matters, order by date and let the column carry the rating.

The template, and the query that does not change itself

The front end is the part people expect to appear on its own. The handbook is direct: “Registering a custom post type does not mean it gets added to the main query automatically.” Your blog index keeps listing posts.

Two template files do the display, named from the identifier: single-{post_type}.php for one review and archive-{post_type}.php for the listing. Copy the theme’s single.php, rename it, change the meta line. That survives a builder, because the template sits outside its control.

For reviews in a block on the home page, a short query in a template part is enough:

$reviews = new WP_Query( array( 'post_type' => 'rshn_review', 'posts_per_page' => 3 ) );

Then loop, print the title, the sector terms and the rating meta, and nothing breaks when the builder changes a widget. Mixing the type into an existing archive belongs on pre_get_posts with a post_type array, guarded the same way. If you have read why the template matters more than the stack, this is that argument at a smaller scale.

The check that takes one request

Load your archive. A 404 means stale rules, which Settings then Permalinks fixes once. A page with nothing on it means the type registered and has no entries. Then ask the site what it registered:

curl -s https://your-site.com/wp-json/wp/v2/types | python3 -m json.tool

Your type should be in that object with its rest_base. If it is missing, show_in_rest is false, the registration never ran, or a cache is serving an old response. If it is there and the entries will not come back, the entries are not public.

The endpoint at the top is the check I keep coming back to: it shows what a site carries, which no settings screen tells you: 14 plugin types across two installs, 8 entries, no archives. Write the 92 lines yourself and the next person finds them in one file instead of a settings screen.

If you are still working out which plugins earn a place, the plugins I actually install is my list. And the headless route is where show_in_rest decides whether your type can be read by anything but a browser.

Request

Got a site that should be doing more?

Send me the address and one sentence about what you sell. I will tell you what I would fix first, and whether it is worth fixing at all.

Start a project Free site audit