Skip to content

CommandCreatePostType

rogertm edited this page Jun 20, 2025 · 2 revisions

$ php cli/wasp create:post_type

Descripción

Crea una nueva clase de Custom Post Type utilizando stubs y la configuración del proyecto.

Uso

create:post_type [options] [--] <name> [<project>]

Argumentos

  • name Nombre del Custom Post Type (ej "Book")
  • project Slug del proyecto donde se debe crear el Custom Post Type (ej: wasp-child). El valor predeterminado es wasp.

Opciones

  • --dry-run Si se especifica, solo simula la creación sin escribir archivos.
  • -h, --help Muestra la ayuda para este comando.

Ejemplo

php cli/wasp create:post_type "Book" 

Crea un archivo en wasp/classes/post-type/class-wasp-post-type-book.php con la siguiente estructura:

<?php
namespace WASP\Post_Type;

use WASP\Posts\Post_Type;

class Post_Type_Book extends Post_Type
{
    public function __construct()
    {
        parent::__construct();

        // CPT slug
        $this->post_type = 'wasp-book';

        // CPT labels
        $this->labels = array(
            'name' => _x( 'Book', 'Post type general name', 'wasp' )
        );

        // CPT arguments
        $this->args = array(
            'public' => true
        );
    }
}

Se escribe una linea de inicialización de la clase en wasp/inc/classes.php:

new WASP\Post_Type\Post_Type_Book;

Clone this wiki locally