...

Press ESC to close

Custom Post Types in WordPress: How to Organize Data

When we install WordPress for the first time, the system offers only two main content publishing structures by default: Posts (linear articles aimed at blogs) and Pages (institutional static content such as ‘About’ and ‘Contact’). However, companies and organizations operate with much richer and more diverse business entities: product catalogs, project portfolios, team members, job openings, testimonials, and case studies.

The creation of Custom Post Types (custom post types) is the technical feature that frees WordPress from the limitations of a simple blog and elevates it to the category of a truly robust and highly organized corporate Content Management System.


Why Use Custom Post Types Instead of Regular Posts?

Trying to force all types of content into standard blog posts using only categories is one of the most serious architectural flaws committed in amateur projects:

  • Pollution of the Editorial Area: Blog writers, HR staff posting jobs and product managers editing catalogs all compete for the same administrative listing, creating operational confusion and the risk of accidental deletions.
  • Clean URL and Permalink Architecture: A dedicated CPT allows you to have your own semantic slugs in the browser (like /portfolio/edificio-horizonte/ or /vacancies/engenheiro-software/) without mixing with the dates or categories of the blog.
  • Exclusive Templates by Content Type: The WordPress file hierarchy automatically recognizes template files as single-{post_type}.php e archive-{post_type}.php, allowing you to design completely different layouts for each entity.
  • Strict Custom Fields: You can associate specific metafields with each type of record (e.g. ‘Salary’ and ‘Location’ field only for Vacancies, and ‘Year’ and ‘Meterage’ only for Projects).

How to Register a Custom Post Type Via Professional Code

Although there are plugins that facilitate the creation of CPTs via the panel, registering them directly in the code through the native hook init is the best practice for corporate projects, ensuring independence from heavy plugins and maximum loading performance:

add_action('init', 'cx_registrar_cpt_projetos');

function cx_registrar_cpt_projetos() {
    $labels = array(
        'name'                  => 'Projetos',
        'singular_name'         => 'Projeto',
        'menu_name'             => 'Projetos',
        'add_new_item'          => 'Adicionar Novo Projeto',
        'edit_item'             => 'Editar Projeto',
        'all_items'             => 'Todos os Projetos',
        'search_items'          => 'Buscar Projetos',
        'not_found'             => 'Nenhum projeto encontrado',
    );

    $args = array(
        'labels'                => $labels,
        'public'                => true,
        'has_archive'           => true,
        'publicly_queryable'    => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-portfolio',
        'show_in_rest'          => true, // Habilita o editor Gutenberg e a REST API
        'supports'              => array('title', 'editor', 'thumbnail', 'excerpt'),
        'rewrite'               => array('slug' => 'projetos', 'with_front' => false),
    );

    register_post_type('projeto', $args);
}

The parameter 'show_in_rest' => true is mandatory in modern development, as it is what enables the Gutenberg block editor and exposes data in the WordPress REST API endpoints (/wp-json/wp/v2/projeto).


Adding Custom Taxonomies to CPT

Just like posts have categories and tags, Custom Post Types require their own taxonomies for sorting and structured filtering:

add_action('init', 'cx_registrar_taxonomia_segmento');

function cx_registrar_taxonomia_segmento() {
    $labels = array(
        'name'          => 'Segmentos',
        'singular_name' => 'Segmento',
        'menu_name'     => 'Segmentos',
    );

    $args = array(
        'labels'            => $labels,
        'hierarchical'      => true, // Comporta-se como categorias (permite subitens)
        'show_ui'           => true,
        'show_in_rest'      => true,
        'rewrite'           => array('slug' => 'segmento'),
    );

    register_taxonomy('segmento', array('projeto'), $args);
}

Table: Examples of Custom Post Types in Business Environments

Commercial Entity CPT slug Associated Taxonomies Typical Custom Metafields
Portfolio / Projects project Segment, Type of Work Customer, Delivery Year, Photo Gallery, Location
Careers / Vacancies vacancy Department, Work Model Salary Range, Requirements, Form Link
Team/Experts team Specialty, Unit Job Title, LinkedIn, Mini Biography, Direct Email
Testimonials / Social Proof testimony Contracted Service Customer Name, Company, Profile Photo, Review Score

Custom Post Types FAQ

What should I do if my CPT links return Error 404?

This is the most common error after registering a new Custom Post Type. WordPress caches URL rewrite rules in the database. To resolve it immediately, go to Settings > Permalinks in the administrative panel and click the button “Save Changes” (without needing to change anything) to recreate the rewrite rules.

Is there a limit to how many CPTs I can create in WordPress?

There is no hard limit imposed by the system core. However, from a software architecture point of view, it is recommended to create only those post types that are strictly necessary to represent distinct data entities, avoiding excessive fragmentation.


Do you need to structure the data architecture and content of your WordPress site with advanced development standards? Discover the solutions software engineering and WordPress themes by Carlos Xavier and build a professional foundation.

Related Articles to Go Deeper

Leave a Reply

Your email address will not be published. Required fields are marked *