Developer Portal
Plugin API Reference

Meta Box API

Add custom fields UI panels to the post editor. Meta boxes appear as collapsible panels on the post create/edit screen and store key-value metadata alongside posts.

📍 Source: App\CMS\MetaBoxes\MetaBoxRegistry

Registering a Meta Box

use App\CMS\MetaBoxes\MetaBoxRegistry;

public function boot(): void
{
    MetaBoxRegistry::register('announcement_options', [
        'title'      => 'Announcement Options',
        'post_types' => ['announcement'],
        'context'    => 'side',       // 'normal', 'side', or 'advanced'
        'priority'   => 'default',    // 'high', 'default', or 'low'
        'fields'     => [
            [
                'key'   => 'is_pinned',
                'label' => 'Pin this announcement',
                'type'  => 'checkbox',
            ],
            [
                'key'     => 'expiry_date',
                'label'   => 'Expiry Date',
                'type'    => 'date',
                'default' => null,
            ],
            [
                'key'   => 'priority_level',
                'label' => 'Priority',
                'type'  => 'select',
                'options' => [
                    'low'    => 'Low',
                    'normal' => 'Normal',
                    'high'   => 'High',
                    'urgent' => 'Urgent',
                ],
                'default' => 'normal',
            ],
        ],
    ]);
}

Method Signature

MetaBoxRegistry::register(string $id, array $options): void

Options Reference

KeyTypeDescription
titlestringDisplay title for the meta box panel
post_typesarrayPost type slugs where this box appears
contextstring'normal', 'side', or 'advanced'
prioritystring'high', 'default', or 'low'
fieldsarrayArray of field definitions (see below)

Field Types

TypeRendered AsExtra Keys
textText inputplaceholder
textareaTextarearows
checkboxCheckbox
selectDropdown selectoptions (key => label array)
dateDate picker input
numberNumber inputmin, max, step
colorColor picker
imageImage upload/URL

Reading & Writing Post Meta

// Read a meta value
$isPinned = $post->getMeta('is_pinned', false);
$expiryDate = $post->getMeta('expiry_date');

// Write a meta value
$post->setMeta('is_pinned', true);
$post->setMeta('priority_level', 'urgent');

// Bulk read all meta for a post
$allMeta = $post->getAllMeta();

💡 Tip: Meta values are stored as key-value pairs in the post_meta table. The core automatically saves meta box field values when the post is saved from the admin editor.

Last verified against AIPostify core. © 2026 AIPostify Marketplace Developer Documentation.