Register a Custom Post Type with Bazooka

First, you need to use Bazooka in Theme or in Plugin.

Register a Post Type

No matter how you organize your-folder/ source folder. You have to create a new class that implements PostTypeInterface like this :

use Fantassin\Core\WordPress\PostType\Contracts\PostTypeInterface;

class YourPostType implements PostTypeInterface
{

  public function getKey(): ?string
  {
    return 'your-post-type';
  }

public function getArgs(): array
  {

    $labels = array(…);

    return [
      'labels'       => $labels,
      'public'       => true,
      'hierarchical' => false,
      'has_archive'  => true,
      'supports'     => ['editor', 'thumbnail', 'excerpt'],
    ];
  }

}

getKey() method must return de Post Type key its corresponds to $post_type parameters in official documentation : https://developer.wordpress.org/reference/functions/register_post_type/

getArgs() method must return an array of the same parameters as $args in official documentation.

That’s all… YourPostType is automatically register by Bazooka in ThemeKernel or PluginKernel.

Even if getArgs return empty array, we convert your Post Type key to Camel Case to get Singular Name and Plural Name.

We advise you to use Plugin to register custom Post Types instead of Theme. By using plugin, tomorrow, if your theme is inactive, you keep your features developed around your Post Types.

Go further :