Articles
Tutorial: Flutter Duplicate Fields
Creating duplicate fields through Freshout’s WordPress plugin, Flutter has been a little on the mysterious side up to this point. No documentation seems to exist for this feature with the exception of simply repeating a php get_post_meta tag for each Custom Field. The true beauty behind the duplicate fields lies within the ability to utilize a single php function to echo all fields as they are created on the fly.
An example:
I set up a Custom Write Panel Page titled “Upcoming Events”. Within this page is a group and the option for duplication is checked. Let’s title this group “Event” and create a Custom Write Fields like so:
CUSTOM FIELD 1:
Name: event-title
Label: Event Title
CUSTOM FIELD 2:
Name: event-date
Label: Event Date
For example purposes, let’s say I’m giving a speech in California on the 5th of July 2011. The first text field, “Event Title”, might be filled in as “IT Security World 2011″ and the second field might be a text field showing the date of “July 5th 2011″. Initially echoing theses fields is straightforward:
<?php echo get_post_meta($post->ID, 'event-title', $single=true) ?> <?php echo get_post_meta($post->ID, 'event-date, $single=true) ?>
If echoing individual, duplicate fields within multiple groups:
<?php echo get('event-title', 1); ?> // Duplicate Group 1, Field 1
<?php echo get('event-title', 2); ?> // Duplicate Group 2, Field 1
The above code works perfectly until the time comes to add in a second or third event that we would like to automate. Keep in mind we are simplifying the situation and the above is assuming that you would not be archiving the events, but merely wanting to show the latest five or six at any given time. This is all well and good until you start clicking that duplicate button and you realize the second or third event doesn’t actually show because the new fields created must have their own individual names in order to exist, something such as “Event1″.
After looking through the Flutter documentation we find a few functions that seem as though they should deliver what we need: getFieldDuplicates ($fieldName, $groupIndex) and getFieldDuplicates ($fieldName, $groupIndex). Unfortunately these only return true values and are not what we are really looking for. What we want is the ability to click the duplicate button and have a single function return the values from the first event group and the next event group and so on.
Not much help has been handed down through the Flutter forums and it seems if anyone does know how to work this, they have been doing a great job of keeping it a secret up to this point. I found only one person willing to shed any kind of light on the matter and as grateful as I am, this was still not enough. Finally through shear frustration I took it upon myself to solve the problem through php. Albert Yarusso was kind enough to assist me in this project. Below is the php function we compiled to display duplicated groups.
<?php $my_query = new WP_Query('page_id=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<?php $total = getGroupDuplicates('event-title');?>
<?php for($i = 1; $i < $total+1; $i++):?>
<?php echo "<div class='event-wrap'>";
echo "<h2>" .get('event-title',$i,1). "</h2>";
echo get('event-date',$i,1);
echo "</div>"; ?>
<?php endfor;?>
<?php endwhile; ?>
Line 1-3:
<?php $my_query = new WP_Query('page_id=1');
To begin, we need to create a WordPress query using our page_id number where the duplicate Custom Fields are located. This could just as easily be a post id number with duplicate fields. The first three lines should be understood as a basic concept from WordPress. If these are not understood, please refer to the WordPress codex on Loops. NOTE: If using this code on a page such as single.php, use the basic loop: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>. The above example is necessary only when calling on a specific post or page.
Line 5:
<?php $total = getGroupDuplicates('event-title');?>
NOTE: This is not the name of the entire group, but the name of the first duplicate field. In this case, these are duplicate groups and not duplicate Custom Fields. This is because we have set the group to duplicate and not the individual fields.
Line 6:
<?php for($i = 1; $i < $total+1; $i++):?>
Start a count for each duplicate group in an effort to process them and add them incrementally.
Line 7:
<?php echo "<div class='event-wrap'>";<
Insert a simple php echo to add a bit of CSS styling for our events. This is only included to demonstrate the ability to add in CSS styling. Any CSS styles are housed within the stylesheet.
Line 8:
echo "<h2>" .get('event-title',$i,1). "</h2>";
Here we are inserting a CSS H2 style tag to the event title to give it a better look, then echo the event titles incrementally and end the H2 tag.
Line 9:
echo get('event-date',$i,1);
Add the event date, which again is done incrementally.
Line 10:
echo "</div>"; ?>
It is then important to end the div tag which opened on line 7.
Line 12:
<?php endfor;?>
Then end the “for” function.
Line 13:
<?php endwhile; ?>
Lastly, don’t forget to close up the WordPress query to finalize the loop.
Now when adding additional duplicate groups on the post or page, the code recognizes that there is more than one group and subsequently echos them all. With a few tries you should have this up and running for any manner of duplicate groups or fields.
85 Comments
Trackbacks
- Using Flutter for a Restaurant Menu in WordPress – sara cannon
- Flutter: Major step in using Wordpress as a CMS | Bryan Williams
- Tutorial: Flutter Duplicate Fields | Doc4 Advertising Agency | WpMash - WordPress News
- Tutorial: Flutter Duplicate Fields
- Tutorial: Flutter Duplicate Fields | Doc4 Advertising Agency
- How to get duplicate fields in flutter – rhizom



How can the code be adjusted to show the most recent duplicate group ON TOP? So for this example, the most recent event listed on top and the rest in order of newest to oldest?
I implemented it, and it works, but newly added duplicates are being displayed at the bottom of the list of the duplicates.
I’m not a PHP developer. Please post code to cut/paste.
THANKS!
if you want to use the getFieldDuplicate ( to duplicate a field and not a group )
Simon,
Your code did not print correctly. Please be sure to wrap it within the “code” or “pre” tags in order for it to display properly. Just in case you didn’t already, please include the initial loop code as well and I will take a look.
Wonder if you can help me, I’m trying to get your tutorial to work, but its just not outputting anything, flutter outputs all the fields fine on their own, but when I try and use the code above it wont display anything.
Its on a page template that I’m trying to get it working. I’m quite new to wordpress and flutter so far you site is the best recource I could find on flutter, so thank’s for your hard work.
Loop is over
Thank you very much for this tutorial!! Very useful!!
Thank you so much. I really appreciate you posting this for everyone, it was very helpful. It’s such a great system and being able to do this is its biggest strength in my opinion.
How would i do duplicate fields if i only wanted to show fields that do not have a check box checked? Thank you for this post. It has really helped me out a lot.
Hi!
This tutorial was very helpful for me, it was awesome.
The only problem that I have is that I made a Group with 2 flutter fields (‘paso_texto’ & ‘paso_imagen’), but when i duplicate it five times, it doesn’t save steps (‘paso’ is step in Spanish) # four and five; it only saves the first three steps…
Am I doing something wrong? Or it’s a known limitation of Flutter?
Thanks!
)
(And sorry for my english…
Very helpful tutorial, thanks.
HI I would like to say: thanks a lot:-) I’m searching google down and above -everybody says: flutter is the best, but to find some help is a hard thing
(and yes my english is more less than my knowledge about flutter
)
Monika from Austria
The primary code to focus on is:
This code should be placed within the loop. If you could link to the sample page I will be happy to take a look.
Hi,
Thanks for this explanation.
I’m testing Flutter right now and I’m not very good at coding. I’m having troubles with where to copy/paste your code
I created a Ressource page on a test blog.
I pasted your code in the page : “Edit page >> Ressources” (I deactivated the WYSIWG) and then renamed the fields so it matches my own ones
But when I’m updating the page, I get strange codes but no datas.
Am I pasting the code in the wrong place ?