logo
logo
logo
  • Home
  • Documentation
  • Support
Get PMF Free

Select

Getting Started

  • What is metafields?
  • Where to use it?
  • Some common use cases for metafields include
  • What about our plugin?

Installations

  • Automatic install from wordpress dashboard
  • Manual install from wordpess dashbaord
  • Install Using FTP

Configs

  • How to use or add?
  • How to print or display or fetch the data?
  • Usage

Fields

  • Text
  • Textarea
  • Switch
  • Tabs
  • Checkbox
  • Select
  • Image
  • Gallery
  • Datepicker
  • Colorpicker
  • Repeater

Go Pro

  • What is included in pro version?
  • Go Pro

FAQs

  • What is a meta box in WordPress?
  • Why do I need a meta box plugin?
  • Can I create multiple meta boxes?
  • Home
  • Docs
  • Fields
  • Select

Select

Template Usage #

Specify the type as select inside the array key called type. Please note that you have to give the type otherwise you will get an error!



<?php // select field dropdown array( 'label' => esc_html__('TP Select Field', 'textdomain'), 'id' => "_your_id", 'type' => 'select', 'options' => array( '1' => 'one', '2' => 'two ', '3' => 'three ', '4' => 'four ', '5' => 'five ', ), 'placeholder' => 'Select an item', 'conditional' => array(), 'default' => '',
'multiple' => false,
) ?>

Notice: Please note that the key field called ‘multiple’ will be always exist in the array otherwise you will get an warning!

Multi Select #

Specify a key called multiple and set it’s value to true or 1. it will be understand that the select is multiple.

<?php
// multi select field dropdown
array(

    'label'           => esc_html__('TP Select Field', 'textdomain'),
    'id'              => "_your_id",
    'type'            => 'select',
    'options'         => array(
        '1' => 'one',
        '2' => 'two ',
        '3' => 'three ',
        '4' => 'four ',
        '5' => 'five ',
    ),
    'placeholder'     => 'Select an item',
    'conditional' => array(),
    'default' => array(),
'multiple' => true ) ?>

Multi Select Context #

Specify a key called ‘context’ you can set it either ‘normal’ or ‘select2’.

<?php
// multi select field dropdown
array(

    'label'           => esc_html__('TP Select Field', 'textdomain'),
    'id'              => "_your_id",
    'type'            => 'select',
    'options'         => array(
        '1' => 'one',
        '2' => 'two ',
        '3' => 'three ',
        '4' => 'four ',
        '5' => 'five ',
    ),
    'placeholder'     => 'Select an item',
    'conditional' => array(),
    'default' => array(),
'multiple' => true,

'context' => 'normal' // or 'select2' ) ?>

How to fetch the data? #

Use our function called tpmeta_field(‘_your_id’) and pass the above array id key to fetch the metadata. Since the function tpmeta_field(‘_your_id’) will return the value so you have to echo the value. 

<?php
$value = function_exists('tpmeta_field')? tpmeta_field('meta_key_id_here') : '';
echo esc_html($value); ?>

Multi select data? #

Use our function called tpmeta_field(‘_your_id’) and pass the above array id key to fetch the metadata. Since the function tpmeta_field(‘_your_id’) will return an array for the multi value.

<?php
$value = function_exists('tpmeta_field')? tpmeta_field('meta_key_id_here') : '';
print_r($value) or use loop; ?>
What are your Feelings
Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Still stuck? How can we help?

How can we help?

Updated on March 18, 2024
CheckboxImage

Powered by BetterDocs

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Contents
  • Template Usage
  • Multi Select
  • Multi Select Context
  • How to fetch the data?
  • Multi select data?

Copyright © 2023 Pure Metafields. All Rights Reserved