Title: [Plugin: Custom Field Template] Repeating custom fields
Last modified: August 19, 2016

---

# [Plugin: Custom Field Template] Repeating custom fields

 *  [infocality](https://wordpress.org/support/users/infocality/)
 * (@infocality)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/)
 * Hi,
 * Im trying to get a repeating area functioning, but it seems to be buggy when 
   you add another “area” , with images going into the first repeat area and content
   not saving correctly.
 * My code is.
 * [intro_animation]
    type = fieldset_open multiple = true multipleButton = true
 * [intro_image]
    label = intro image: type = textarea rows = 20 cols = 20 mediaButton
   = true mediaOffVideo = true mediaOffMedia = true mediaOffAudio= true tinyMCE 
   = true
 * [intro_text]
    label = intro text: type = textarea rows = 5 cols = 20 mediaButton
   = true mediaOffVideo = true mediaOffMedia = true mediaOffAudio= true mediaOffImage
   = true tinyMCE = true
 * [intro_order]
    label = intro order: type = text
 * [intro_animation]
    type = fieldset_close
 * Can I group multi custom fields in a repearable fieldset ?
 * Thanks
 * bill

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Hiroaki Miyashita](https://wordpress.org/support/users/hiroaki-miyashita/)
 * (@hiroaki-miyashita)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522505)
 * In order to save all values in the right fields, you need to add `blank = true`
   attribute. Even if you make the field blank, the blank value will be created.
   BTW, I tried your code, and I noticed it seemed that multiple tinyMCE textareas
   are not working properly. You had better use the normal textarea….
 *  Thread Starter [infocality](https://wordpress.org/support/users/infocality/)
 * (@infocality)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522812)
 * does the blank = true have to be in teh fieldset or the actual field. Also how
   do we control the ordering of items ..
 *  [proximity2008](https://wordpress.org/support/users/proximity2008/)
 * (@proximity2008)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522816)
 * Hi Inforcality,
 * At the moment I am doing something incredibly similar 😉
    Here is what I came
   up with:
 * MY CFT CODE:
 *     ```
       [project]
       type = fieldset_open
       multiple = true
       multipleButton = true
   
       [project_name]
       type = textfield
       size = 35
       label = Project Name
       class = project_name
       blank = true
   
       [project_image]
       type=file
       relation=true
       label = upload image
       class = project_image
       blank = true
   
       [project_type]
       type=select
       value = WordPress # Joomla!  # Static
       class = project_type
       blank = true
   
       [project_description]
       type=textarea
       rows=10
       cols = 30
       label = Description of Project
       class = project_description
       blank = true
   
       [project_link]
       label = Link to project
       type = text
       size = 35
       class = project_link
       blank = true
   
       [project]
       type = fieldset_close
       ```
   
 * So that will give you a rather jumbled data in the database.
    The trick is the
   naming of the fields (you’ve got that sorted I see), I’ve used “project”. That
   will make it easier to retrieve and sort the data.
 * In your template:
 *     ```
       // retrieve entries with project prefix
       				$sql = " SELECT * FROM $wpdb->postmeta	WHERE post_id = $post->ID AND meta_key LIKE '%project%' ORDER BY <code>meta_id</code> ASC";
       				$data_objects = $wpdb->get_results($sql);
       				$project = array();
       				$i = 0;
   
       				foreach($data_objects as $data) {
   
       					// the name of the fieldset:
       					if($data->meta_key == 'project') {
       						$limit = $data->meta_value;
       					}
   
       					$i = ( $i <= $limit ) ? $i : 1;
   
       					if( $data->meta_value != $limit ) {
       					$project[$i]["$data->meta_key"] = $data->meta_value;
       					}
       					$i++;
       				}
       				//check data
       				//print_r($project);
   
       				foreach( $project as $key){
       					// you will need to check if the value is blank but you get the idea.
       					echo 'Project Name: ' . $key['project_name'] .'<br />';
       					echo 'Project Image: ' . $key['project_image'] .'<br />';
       					echo 'Project Type: '.  $key['project_description'] .'<br />';
       					// etc....
       				}
       ```
   
 * I’m not the greatest programmer in the world but that should do it. It is untested
   at the moment and there are no data checks. But you get the idea.
 *  [Marcin Biegun](https://wordpress.org/support/users/biegun/)
 * (@biegun)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522839)
 * Thank you for that piece of code- it was very helpful.
    I still have a feeling,
   that it could be less complex- any idea of other workaround?
 * There also should be change from
    `$limit = $data->meta_value;` to `$limit = 
   $data->meta_value+1;` – otherwise you miss last row.
 *  [proximity2008](https://wordpress.org/support/users/proximity2008/)
 * (@proximity2008)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522843)
 * There is one more major caveat to this repeating technique. You can’t use tinymce
   or html textarea content types.
 * When you push the “Add New” on the fieldset all the code is duplicated. You do
   get a new field but TinyMCE and the HTML editor are still tied to the original
   content area.
 * So when you use any javascript, it will affect the original textarea not the 
   newly created one.
 * I’d love a fix for this.
 *  [cugok](https://wordpress.org/support/users/cugok/)
 * (@cugok)
 * [15 years ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522871)
 * Great fix!
 * But if I’m editing post and before I’ve added minimum 2 records, I see only delete
   button (no “Add new” button!?)
 * If I wan to add I’ve to delete all and then add all one more time.
    My code:
 * [founder]
    type = fieldset_open multiple = true multipleButton = true
 * [founder_txt]
    hideKey = true type = text size = 50 label = Founder – Enter name
   and title class founder_txt blank = true
 * [founder_img]
    hideKey = true type = file label = Founder – Upload photo class
   = founder_img blank = true
 * [class]
    type = fieldset_close
 * Screenshot: [http://imageshack.us/m/716/7684/cftvl.jpg](http://imageshack.us/m/716/7684/cftvl.jpg)
 *  [Ignacio Nelson](https://wordpress.org/support/users/subwaydesign/)
 * (@subwaydesign)
 * [15 years ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522873)
 * Hi cugok. You are opening and closing a fieldset with different names. That might
   be the problem.
 * Try changing the name of the opening or closing tag to match the other one. It
   might be a good idea to name them founder_fieldset.
 *  [cugok](https://wordpress.org/support/users/cugok/)
 * (@cugok)
 * [15 years ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522874)
 * Hey Ignacio! Thanks for fix! It works fine now 😉

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘[Plugin: Custom Field Template] Repeating custom fields’ is closed to
new replies.

 * 8 replies
 * 6 participants
 * Last reply from: [cugok](https://wordpress.org/support/users/cugok/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/plugin-custom-field-template-repeating-custom-fields/#post-1522874)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
