-
Notifications
You must be signed in to change notification settings - Fork 0
CommandCreatePostType
rogertm edited this page Jun 20, 2025
·
2 revisions
Crea una nueva clase de Custom Post Type utilizando stubs y la configuración del proyecto.
create:post_type [options] [--] <name> [<project>]-
nameNombre del Custom Post Type (ej "Book") -
projectSlug del proyecto donde se debe crear el Custom Post Type (ej:wasp-child). El valor predeterminado eswasp.
-
--dry-runSi se especifica, solo simula la creación sin escribir archivos. -
-h, --helpMuestra la ayuda para este comando.
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;