PHP code example of pollora / metabox

1. Go to this page and download the library: Download pollora/metabox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pollora / metabox example snippets


use Pollora\Metabox\FieldGroup;
use Pollora\Metabox\Fields\Number;
use Pollora\Metabox\Fields\Text;
use Pollora\Metabox\Location;

FieldGroup::make('Event', 'event')
    ->location(Location::postTypes('page'))
    ->context('side')
    ->fields([
        Text::make('Venue', 'venue')
            ->placeholder('Where does it take place?')
            ->

use Pollora\Metabox\Block;
use Pollora\Metabox\Fields\Group;
use Pollora\Metabox\Fields\Text;
use Pollora\Metabox\Fields\Url;

Block::make('Useful links', 'useful-links')
    ->icon('admin-links')
    ->category('widgets')
    ->renderTemplate(get_theme_file_path('blocks/useful-links.php'))
    ->fields([
        Text::make('Title', 'title'),
        Group::make('Links', 'links')
            ->cloneable()
            ->addButton('Add a link')
            ->fields([
                Text::make('Label', 'label'),
                Url::make('URL', 'url'),
            ]),
    ]);

use Pollora\Metabox\FieldGroup;
use Pollora\Metabox\Fields\Email;
use Pollora\Metabox\Location;
use Pollora\Metabox\SettingsPage;

SettingsPage::make('Site options', 'site-options')
    ->icon('admin-generic')
    ->optionName('site_options');

FieldGroup::make('Contact', 'contact')
    ->location(Location::settingsPages('site-options'))
    ->fields([
        Email::make('Contact email', 'contact_email'),
    ]);

use Pollora\Metabox\FieldGroup;
use Pollora\Metabox\Fields\Number;
use Pollora\Metabox\Fields\Select;
use Pollora\Metabox\Fields\Url;
use Pollora\Metabox\Location;
use Pollora\Metabox\Rules\Rule;

$linkType = Select::make('Link type', 'link_type')
    ->options(['page' => 'Page', 'custom' => 'Custom URL']);

FieldGroup::make('Call to action', 'cta')
    ->location(Location::postTypes('page'))
    ->context('side')
    ->include(Rule::template('templates/landing.php'))
    ->fields([
        $linkType,
        Url::make('URL', 'cta_url')->visibleWhen($linkType, 'custom')->

add_filter('rwmb_meta_boxes', function (array $metaBoxes): array {
    $metaBoxes[] = [
        'id' => 'cta',
        'title' => 'Call to action',
        'post_types' => ['page'],
        'context' => 'side',
        'include' => [
            'relation' => 'AND',
            'template' => ['templates/landing.php'],
        ],
        'fields' => [
            [
                'type' => 'select',
                'name' => 'Link type',
                'id' => 'link_type',
                'options' => ['page' => 'Page', 'custom' => 'Custom URL'],
            ],
            [
                'type' => 'url',
                'name' => 'URL',
                'id' => 'cta_url',
                'visible' => ['link_type', '=', 'custom'],
                '