PHP code example of maheshwaghmare / wp-meta-fields
1. Go to this page and download the library: Download maheshwaghmare/wp-meta-fields 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/ */
maheshwaghmare / wp-meta-fields example snippets
composer
// Load files.
ox "Example Meta Box" for the post type 'post' and 'page'.
mf_add_meta_box( array(
'id' => 'example-meta-box',
'title' => __( 'Example Meta Box' ),
'screen' => array( 'post', 'page' ),
'context' => 'normal',
'priority' => 'default',
'fields' => array(
'prefix-1-text' => array(
'type' => 'text',
'title' => __( 'Text Field', 'textdomain' ),
'description' => __( 'Simple text field for demonstration purpose.', 'textdomain' ),
'hint' => __( 'This is the Text Field for storing the text data for demonstration purpose.', 'textdomain' ),
'default' => '',
),
)
));
composer remove maheshwaghmare/wp-meta-fields --update-with-dependencies
mf_add_meta_box( array(
'id' => 'example-all-fields',
'title' => __( 'Example - All Fields' ),
'screen' => array( 'post' ),
'context' => 'normal',
'priority' => 'default',
'fields' => array(
// ..
)
));
mf_add_meta_box( array(
'id' => 'example-meta-box',
'title' => __( 'Example Meta Box' ),
'screen' => array( 'post' ),
'context' => 'normal',
'priority' => 'default',
'fields' => array(
'prefix-1-text' => array(
'type' => 'text',
'title' => __( 'Text Field', 'textdomain' ),
'description' => __( 'Simple text field for demonstration purpose.', 'textdomain' ),
'hint' => __( 'This is the Text Field for storing the text data for demonstration purpose.', 'textdomain' ),
'default' => '',
),
)
));
[mf meta_key='prefix-1-text']
or
mf_meta( 'prefix-1-text' );
or
echo mf_get_meta( 'prefix-1-text' );
/**
* Meta Fields (Screen - Normal)
*/
mf_add_meta_box( array(
'id' => 'example-all-fields',
'title' => __( 'Example - All Fields' ),
'screen' => array( 'post' ),
'context' => 'normal',
'priority' => 'default',
'fields' => array(
'prefix-1-text' => array(
'type' => 'text',
'title' => 'Text Field',
'description' => 'Text Field field description goes here.',
'hint' => 'Text Field field description goes here.',
'default' => '',
),
'prefix-1-textarea' => array(
'type' => 'textarea',
'title' => 'Textarea',
'description' => 'Textarea field description goes here.',
'hint' => 'Textarea field description goes here.',
'default' => '',
),
'prefix-1-password' => array(
'type' => 'password',
'title' => 'Password',
'description' => 'Password field description goes here.',
'hint' => 'Password field description goes here.',
'default' => '',
),
'prefix-1-color' => array(
'type' => 'color',
'title' => 'Color',
'description' => 'Color field description goes here.',
'hint' => 'Color field description goes here.',
'default' => '#f3f3f3',
),
'prefix-1-date' => array(
'type' => 'date',
'title' => 'Date',
'description' => 'Date field description goes here.',
'hint' => 'Date field description goes here.',
'default' => '',
),
'prefix-1-datetime-local' => array(
'type' => 'datetime-local',
'title' => 'Date Time Local',
'description' => 'Date Time Local field description goes here.',
'hint' => 'Date Time Local field description goes here.',
'default' => '',
),
'prefix-1-email' => array(
'type' => 'email',
'title' => 'Email',
'description' => 'Email field description goes here.',
'hint' => 'Email field description goes here.',
'default' => '',
),
'prefix-1-month' => array(
'type' => 'month',
'title' => 'Month',
'description' => 'Month field description goes here.',
'hint' => 'Month field description goes here.',
'default' => '',
),
'prefix-1-number' => array(
'type' => 'number',
'title' => 'Number',
'description' => 'Number field description goes here.',
'hint' => 'Number field description goes here.',
'default' => '',
),
'prefix-1-time' => array(
'type' => 'time',
'title' => 'Time',
'description' => 'Time field description goes here.',
'hint' => 'Time field description goes here.',
'default' => '',
),
'prefix-1-week' => array(
'type' => 'week',
'title' => 'Week',
'description' => 'Week field description goes here.',
'hint' => 'Week field description goes here.',
'default' => '',
),
'prefix-1-url' => array(
'type' => 'url',
'title' => 'Url',
'description' => 'Url field description goes here.',
'hint' => 'Url field description goes here.',
'default' => '',
),
'prefix-1-checkbox' => array(
'type' => 'checkbox',
'title' => 'Checkbox',
'description' => 'Checkbox field description goes here.',
'hint' => 'Checkbox field description goes here.',
'default' => true,
),
'prefix-1-radio' => array(
'type' => 'radio',
'title' => 'Radio',
'description' => 'Radio field description goes here.',
'hint' => 'Radio field description goes here.',
'default' => 'one',
'choices' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
),
),
'prefix-1-select' => array(
'type' => 'select',
'title' => 'Select',
'description' => 'Select field description goes here.',
'hint' => 'Select field description goes here.',
'default' => 'one',
'choices' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
),
),
)
) );
mf_meta( 'prefix-1-text' );
mf_meta( 'prefix-1-text', 46 );
echo mf_get_meta( 'prefix-1-text' );
echo mf_get_meta( 'prefix-1-text', 46 );