duplicate fields - please help

29 views
Skip to first unread message

Rich

unread,
Mar 17, 2009, 12:36:10 PM3/17/09
to Flutter Support
Can someone please help me with this. I need to know how to call
duplicate fields in my template. Please help.

Thanks.
Rich

na...@freshout.us

unread,
Mar 19, 2009, 1:09:46 PM3/19/09
to Flutter Support
<?php $total = getGroupDuplicates('Teamname');?>
<?php for($i = 1; $i < $total+1; $i++):?>
<div class="prow">
<div class="pr-left"><img src="<?=PT()?>?src=<?=get
('Teamphoto',$i,1)?>&w=100"?></div>
<div class="pr-right">
<p><strong><?php echo get('Teamname',$i,1);?></
strong><br /><?php echo get('Teambiography',$i,1);?></p>
</div>
</div>
<?php endfor;?>
</div>

swoosh

unread,
Mar 20, 2009, 11:46:36 AM3/20/09
to Flutter Support
How we know the group index??

I have duplicate fields, the name of the fields is 'image' and the
type 'image'. There are simply in a panel, i have no group.

How can access them?
> >duplicatefields in my template. Please help.
>
> > Thanks.
> > Rich

Rich

unread,
Mar 20, 2009, 12:13:24 PM3/20/09
to Flutter Support
swoosh,

Try this:

<?php $total = getGroupDuplicates('image');?>
<?php for($i = 1; $i < $total+1; $i++):?>
<div class="prow">
<img src="<?=PT()?>?src=<?=get
('image',$i,1)?>&w=100"?>
</div>
<?php endfor;?>

swoosh

unread,
Mar 22, 2009, 2:49:00 PM3/22/09
to Flutter Support
Thanx for your help Rich.

But the code don't work. I notice that the getGroupDuplicates return
1, or in my "article" i have uploaded two images also i have one
duplicate field "image" with two uploaded images (label are "image" &
"image(2)").
I don't understand why you use the getGroupDuplicates? In the
documentation i read : Get number of group duplicates given field
name. Or i want the number of duplicates fields "image" why use a
group function? :-§

Sorry for my english and thanx again.

On 20 mar, 17:13, Rich <rich.b.des...@gmail.com> wrote:
> swoosh,
>
> Try this:
>
> <?php $total = getGroupDuplicates('image');?>
>        <?php for($i = 1; $i < $total+1; $i++):?>
>            <div class="prow">
>               <img src="<?=PT()?>?src=<?=get
> ('image',$i,1)?>&w=100"?>
>            </div>
>        <?php endfor;?>
>
> On Mar 20, 10:46 am, swoosh <mathieu.houlb...@gmail.com> wrote:
>
> > How we know the group index??
>
> > I haveduplicatefields, the name of the fields is 'image' and the

Karl

unread,
Mar 23, 2009, 3:30:20 PM3/23/09
to Flutter Support
Sorry if im being really dense but its been a long few weeks. Im using
the following code for tracks in an album:

<?php $total = getFieldDuplicates('track', 1);?>
<?php for($i = 1; $i < $total+1; $i++):?>

<ul><li> <?php echo get
('track',$i,1)?></li></ul>

<?php endfor;?>

It kinda works, the loop itterates for the amount of duplicate fields
(tracks) but only returns the first value...then the last value, n-1
times.

So for example I have the tracks:
1. "Intro"
2. "Into the Infinity of Thoughts"
3. "The Burning Shadows of Silence"
4. "Cosmic Keys to My Creations and Times"
5. "Beyond the Great Vast Forest"
6. "Towards the Pantheon"
7. "The Majesty of the Night Sky"
8. "I Am the Black Wizards"
9. "Inno a Satana"

The above code returns:

1. "Intro"
2. "Inno a Satana"
3. "Inno a Satana"
4. "Inno a Satana"
5. "Inno a Satana"
6. "Inno a Satana"
7. "Inno a Satana"
8. "Inno a Satana"
9. "Inno a Satana"

Thanks in advance for any help

swoosh

unread,
Mar 23, 2009, 7:08:29 PM3/23/09
to Flutter Support
Ok it's work !!!

Karl try this :

<?php $total = getFieldDuplicates('track', 1);?>
<?php for($i = 1; $i < $total+1; $i++):?>

<ul><li> <?php echo get
('track',1,$i)?></li></ul>

<?php endfor;?>

In the line :<?php echo get('track',$i,1)?> the $i variable represents
the group or you need to have the duplicate field in the variable for
that just do this : <?php echo get('track',1,$i)?>

I hope this work for you

Thanx

Karl

unread,
Mar 24, 2009, 6:01:56 AM3/24/09
to Flutter Support
Arr wow, that has to go with one of the most blindingly obvious
mistakes any one has ever made!!!

Cheers Swoosh, it works a treat :)

eyegaze

unread,
Mar 25, 2009, 8:27:13 AM3/25/09
to Flutter Support
I have successfully created a loop like you good folks have been
discussing here but then a problem cropped up when I removed one of
the duplicates.

I had created a list of staff members for a company page but when
number 2 on the list left and a replacement joined the CMS operaration
fell down.

The space created by the deletion in the sequence of IDs was filled on
the web page by a duplicate of a name from further down the list and
the replacement does not appear at all. I am thiking that this problem
is caused by the hole in the sequence. Whereas i had IDs 1 to 9, now I
have IDs 1 to 10 except number 2 is missing.

Any thought or ideas?

Many thanks
Neil

eyegaze

unread,
Mar 27, 2009, 7:36:19 AM3/27/09
to Flutter Support
Hi

Reading back I don't think I was very clear with my explanation of my
problem.

The basic issue is that when I loop Group Duplicates everything worked
well until I had to delete an entry from the middle of the duplicate
list. The loop still counts the now deleted ID and displays the wrong
information.

Please let me know if anybody has a solution to this. If I create a
new group duplicate it adds it to the bottom as opposed to using the
deleted ID.

This is the code I am using:

<!-- Staff Member -->
<?php $i=1; ?>
<?php $group_dup = getGroupDuplicates ("person_name"); ?>
<?php for($i = 1; $i < $group_dup+1; $i++): ?>
<div id="staff_member">
<h3><? echo get("person_name", $i,1); ?> - <? echo get("job_title",
$groupIndex); ?></h3>
<p><? echo get_image("person_photo", $i,1); ?>
<? echo get("person_description", $i,1); ?></p></div>
<?php endfor; ?>
<!-- End of Staff Member -->

Many thanks
Neil

CKeim

unread,
Apr 10, 2009, 12:38:09 AM4/10/09
to Flutter Support
What if you have duplicate fields with a group that can be
duplicated? I can't get it to work...using this right now.

<?php query_posts('pagename=photos'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $fotal = getGroupDuplicates('photo-album-name');?>
<?php for($b = 1; $b < $fotal+1; $b++):?>
<div class="photo-album">
<?php echo get('photo-album-name',$b,1);?><br />
<?php $total = getFieldDuplicates('albimg', 1);?>
<?php for($i = 1; $i < $total+1; $i++):?>

<ul><li> <?php echo get
('albimg',1,$i)?></li></ul>


I just get the same albimg for both groups.

On Mar 27, 7:36 am, eyegaze <m.a.cana...@eyegaze.tv> wrote:
> Hi
>
> Reading back I don't think I was very clear with my explanation of my
> problem.
>
> The basic issue is that when I loop Group Duplicates everything worked
> well until I had to delete an entry from the middle of theduplicate
> list. The loop still counts the now deleted ID and displays the wrong
> information.
>
> Please let me know if anybody has a solution to this. If I create a
> new groupduplicateit adds it to the bottom as opposed to using the

lacohido

unread,
May 3, 2009, 5:41:39 PM5/3/09
to Flutter Support
Im having the same Problem. Any Help with this?

On Mar 27, 4:36 am, eyegaze <m.a.cana...@eyegaze.tv> wrote:
> Hi
>
> Reading back I don't think I was very clear with my explanation of my
> problem.
>
> The basic issue is that when I loop Group Duplicates everything worked
> well until I had to delete an entry from the middle of the duplicate
> list. The loop still counts the now deleted ID and displays the wrong
> information.
>
> Please let me know if anybody has a solution to this. If I create a
> new group duplicate it adds it to the bottom as opposed to using the
> deleted ID.
>
> This is the code I am using:
>
> <!-- Staff Member -->
> <?php $i=1; ?>
>   <?php $group_dup =getGroupDuplicates("person_name"); ?>

Bedoz

unread,
May 7, 2009, 9:33:00 AM5/7/09
to Flutter Support
i have the same problem how can i solve it?

Thank you

Bedoz

unread,
May 7, 2009, 11:40:44 AM5/7/09
to Flutter Support
i have found a solution for this problem.

i have rewritten get function using this into main.php

function get_fields($fieldName)
{
global $post;
global $wpdb;

$result = $wpdb->get_results("
SELECT meta_value
FROM $wpdb->postmeta
WHERE post_id = '$post->ID' and meta_key = '$fieldName'
ORDER BY meta_id
", ARRAY_A );
$i = 0;
while (isset($result[$i]['meta_value'])) {
$ret[] = $result[$i]['meta_value'];
$i++;
}
return $ret;
}

it will return an array of all single or duplicated fields with name
given to function
Hope this help!

gagou

unread,
Jun 3, 2009, 6:03:22 PM6/3/09
to Flutter Support
The answer would be :
<ul>
<? echo $total = getGroupDuplicates ('your_item_id'); ?>
<?php for($i = 1; $i < $total+1; $i++):?>
<li>
<? echo get_image('your_item_id', $i); ?>
</li>
<?php endfor;?>
</ul>

Am I right
See ya...
On May 7, 5:40 pm, Bedoz <bedo...@gmail.com> wrote:
> i have found a solution for this problem.
>
> i have rewritten get function using this into main.php
>
> function get_fields($fieldName)
> {
>         global $post;
>         global $wpdb;
>
>         $result = $wpdb->get_results("
>                 SELECT meta_value
>                 FROM $wpdb->postmeta
>                 WHERE post_id = '$post->ID' and meta_key = '$fieldName'
>                 ORDER BY meta_id
>         ", ARRAY_A );
>         $i = 0;
>         while (isset($result[$i]['meta_value'])) {
>                 $ret[] = $result[$i]['meta_value'];
>                 $i++;
>         }
>         return $ret;
>
> }
>
> it will return an array of all single or duplicated fields with name
> given to function
> Hope this help!
>
> On 7 Mag, 15:33, Bedoz <bedo...@gmail.com> wrote:
>
> > i have the same problem how can i solve it?
>
> > Thank you
>
> > On 10 Apr, 06:38, CKeim <Caroline.K...@gmail.com> wrote:
>
> > > What if you haveduplicatefields with a group that can be

Maguar

unread,
Jun 3, 2009, 11:13:03 PM6/3/09
to Flutter Support
how to display all the fields clear and works well! But do the
duplication of 3 photos for example, No. 1 = 1.jpg, No. 2 = 2.jpg, No. 3 =
3.jpg all displayed excellent! Now remove the number 2 and then
refresh the page! Conclusion incorrect! In this case, total = 2,
picture number 2 should be = 3.jpg! Ie after removing duplicate photos
of his id is not changed!

gagou

unread,
Jun 4, 2009, 10:24:21 AM6/4/09
to Flutter Support
I'm not sure to understand what you're saying.
It works perfectly for me even if I remove duplicated images. Well,
actually, duplicated groups : I tried to duplicate image fields inside
a group but they keep disappearing when I save my post. So I didn't
even try to use them in my theme.
There must be a huge problem with the way id are dispatched, if that
is what you are pointing.
But I believe each image you insert should have at least a description
associated (which could be useful in many ways : title, alt,
caption...), so the duplicated groups will do for me.
Message has been deleted

thang

unread,
Jun 24, 2009, 11:31:59 AM6/24/09
to Flutter Support
I faced with the same problem and after spent 1 hours to look through
the internet, I found the solution.

In the file get-custom.php add this function:

/** Developed by Thang
* Return a array with the all distinct values in one array
*
* @param string $groupName
*/
function getDistinctGroupOrder(){
global $post,$wpdb;

$elements = $wpdb->get_results("SELECT DISTINCT group_count FROM
".RC_CWP_TABLE_POST_META." WHERE post_id = ".$post->ID." ORDER BY
order_id ASC");

foreach($elements as $element){
$order[] = $element->group_count;
}

return $order;
}

---------------------------------------------------
Here is my for loop:

$group_orders = getDistinctGroupOrder();

foreach($group_orders as $group_order)
{
$value= get('field',$group_order,1);
}

-----------------------------------------------------

lacohido

unread,
Jul 1, 2009, 9:40:03 PM7/1/09
to Flutter Support
THANG!!!-
You did it! Thank you so much! Ive spent hours trying to figure this
out. The Flutter Devs need to implement your Function.
Thanks again

doc4

unread,
Jul 13, 2009, 1:32:26 AM7/13/09
to Flutter Support
I've written a tutorial on this same issue:

http://www.doc4design.com/articles/flutter-duplicate-fields/

Dale Crum
http://www.doc4design.com

snackd

unread,
Aug 4, 2009, 4:17:06 PM8/4/09
to Flutter Support
okay, so assuming that this doesn't get fixed by the flutter devs, i
see two fixes here for do-it-yourselfers. Bedoz's and thang's. both
look pretty similar, in the way they access the wp db directly. it
looks like Bedoz's only gets one field at a time, but it would be
fairly trivial to rewrite this as a loop-of-loops that got ALL fields.
also they each say to place them in different files.

does anyone have any opinions or critique? is one method more
reliable? is there something missing? most importantly, do they in
fact produce ALL groups/fields and NONE of the deleted groups/fields?

personally, if i'm going to continue using flutter, it's pretty
important to have codified solutions to stuff like this so that i can
use my time on other things.

cheers all & good work!
> > > >                         <? echoget_image('your_item_id', $i); ?>
> > > > > > > >   <p><? echoget_image("person_photo", $i,1); ?>

Nick Keenan

unread,
Aug 18, 2009, 2:04:18 PM8/18/09
to Flutter Support
Thang, brilliance. You just saved my recursive butt.

One slight change to your code, to allow for code that requires
multiple duplicate groups on the same page (as mine does)

/** Developed by Thang
* Return a array with the all distinct values in one array
*
* @param string $groupName
*/

function getDistinctGroupOrder($field_name){
global $post,$wpdb;
$elements = $wpdb->get_results("SELECT DISTINCT group_count FROM
".RC_CWP_TABLE_POST_META." WHERE post_id = ".$post->ID." AND
field_name = '".$field_name."' ORDER BY order_id ASC");
foreach($elements as $element){
$order[] = $element->group_count;
}
return $order;
}

Same usage, just specify a specific field name in the group:

$group_orders = getDistinctGroupOrder('duplicated-group-field');

*** Right? This change doesn't screw anything up, right? ***

THANK YOU for figuring this out.

JessN

unread,
Sep 17, 2009, 8:19:32 PM9/17/09
to Flutter Support
I know this is a bit old but I wanted to add something that I found.
As you guys mentioned above, if you delete an entry the system still
wants to show something there. I ran into this problem not with
duplicate groups or fields but just using Flutter code inside a loop.
When an entry was deleted it just pulled up an empty space where the
content used to be. Here's what I ended up doing and it works well:

<!-- check to see if there's actually content filled in. -->
<?php
$content = get_post_meta($post->ID, 'book_title', true);
if ($content) { ?>

Flutter code and other content here

<?php } else { ?>

<?php } ?>

Basically it just checks to see if there's actually content filled
in. If the space for the old post is still there on the server (even
though it was deleted) the content will be blank. If it's blank then
it returns nothing and moves onto the next post. Just replace
'book_title' with one of the names of your fields.

mroggle

unread,
Sep 24, 2009, 2:42:38 PM9/24/09
to Flutter Support
THANG and NICK, thank you so much for your solutions!!

i used Nicks modification, but changed it to "ORDER BY field_name",
which gave me all the control i needed!

one strange quirk tho, it didnt accept DESC instead of ASC. it just
kept returning it in descending order.

but, i threw in a good old array reverse before the output. is that
too mean?

thanks again, seriously!



On Aug 18, 7:04 pm, Nick Keenan <worldtheatre...@gmail.com> wrote:
> Thang, brilliance.  You just saved my recursive butt.
>
> One slight change to your code, to allow for code that requires
> multipleduplicategroups on the same page (as mine does)
Reply all
Reply to author
Forward
0 new messages