Corcel\Post::registerPostType PHP Method

registerPostType() public static method

This method allows you to register classes that will be used for specific post types as defined in the post_type column of the wp_posts table. If a post type is registered here, when a Post object is returned from the posts table it will be automatically converted into the appropriate class for its post type. If you register a Page class for the post_type 'page', then whenever a Post is fetched from the database that has its post_type has 'page', it will be returned as a Page instance, instead of the default and generic Post instance.
public static registerPostType ( string $name, string $class )
$name string The name of the post type (e.g. 'post', 'page', 'custom_post_type')
$class string The class that represents the post type model (e.g. 'Post', 'Page', 'CustomPostType')
    public static function registerPostType($name, $class)
    {
        static::$postTypes[$name] = $class;
    }

Usage Example

Beispiel #1
0
 public function testPostTypeConstructor()
 {
     Post::registerPostType('video', 'Video');
     $post = new Post();
     $model = $post->newFromBuilder(['post_type' => 'video']);
     $this->assertInstanceOf("Video", $model);
 }
All Usage Examples Of Corcel\Post::registerPostType