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

Repeater

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
  • Repeater

Repeater

Template Usage #

<?php
array(
    'label'     => esc_html__('Field Title', 'textdomain'),
    'id'        => "_your_id",
    'type'      => 'repeater', // specify the type "repeater" (case sensitive)
    'conditional'   => array(),
    'default'       => array(),
    'fields'        => array(
        array(
            'label'           => esc_html__('Your Title', 'textdomain'),
            'id'              => "_your_id",
            'type'            => 'select',
            'options'         => array(
                'footer_1' => 'Footer 1',
                'footer_2' => 'Footer 2',
                'footer_3' => 'Footer 3'
            ),
            'placeholder'     => 'Select a footer',
            'conditional' => array(),
            'default' => 'footer_1',
        ),
        array(
            'label'           => esc_html__('Select Footer Style', 'textdomain'),
            'id'              => "_footer_style_2",
            'type'            => 'select',
            'options'         => array(
                'footer_1' => 'Footer 1',
                'footer_2' => 'Footer 2',
                'footer_3' => 'Footer 3'
            ),
            'placeholder'     => 'Select a footer',
            'conditional' => array(),
            'default' => 'footer_1',
            'bind'    => "_footer_template_2" // bind the key to be control with conditions
        ),
        array(
            'label'           => esc_html__('Select Footer Template', 'textdomain'),
            'id'              => "_footer_template_2",
            'type'            => 'select_posts',
            'placeholder'     => 'Select a template',
            'post_type'       => 'tp-footer',
            'conditional' => array(
                "_footer_style_2", "==", "footer_2" // First parameter will be the id of control field and so on
            ),
            'default' => '',
        )
    )
)
?>

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 an array so you have to echo the value inside a loop. 

Access the field’s value or subfield with it’s id key from the array.

<?php
$tp_repeater = function_exists('tpmeta_field') ? tpmeta_field('repeater_meta_key') : ''; // tpmeta_field($meta_key, $post_id)

foreach($tp_repeater as $row){ // Iterate the data with loop
    echo $row['repeater_sub_field_key'] // get the subfield value by repeater inner array field key
}
?>
What are your Feelings
Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Still stuck? How can we help?

How can we help?

Updated on October 3, 2023
Colorpicker

Powered by BetterDocs

Leave a Reply Cancel reply

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

Table of Contents
  • Template Usage
  • How to fetch the data?

Copyright © 2023 Pure Metafields. All Rights Reserved