• Hi there,

    I’m using the Magic Fields plugin (version 1.5.8.3, not the newer v2)

    I’ve created a write panel where I can create duplicate groups.

    In each group I have a field for the group title, which is not duplicated. I then have another fields for the group items, which can be duplicated.

    I’m struggling to output all of this. It seems from reading the documentation that it can be done, but it all refers to specifying the group & field ID’s you want to show, not for just automatically outputting everything?

    This code works, but it relies on me telling it which group ID I want to display the duplicates fields for:

    <?php
    	$mygroup = get_group('GroupName'); // use the Custom Group name
    	foreach($mygroup as $group) {
    ?>
    
    	<h1><?php echo $group['normal_field_name'][1]; // display a title for the group using a non-duplicated field ?></h1>
    
    	<?php
    		$fields = get_field_duplicate('duplicated_field_name',999); // get all the group items using duplicated fields
    		foreach($fields as $field) {
    	?>
    
    		<p><a href="<?php echo get_permalink($field); ?>" title="<?php echo get_the_title($field); ?>"><?php echo get_the_title($field); ?></a></p>
    
    	<?php } ?>
    
    <?php } ?>

    999 shows where I am told to specify the ID number of the group. How can I set this to retrieve the ID of the group displayed?

    $group returns an array, not an ID number.

    Just to add a little more complication, my duplicated field is a related type fields, hence the slightly complicated duplicate field code, which needs to retrieve the permalink & title for each related type field. This works fine though, i just can’t display the different groups!

    Any ideas anyone?

    I would guess this would be a fairly normal use of the duplicate fields and groups? I’m not sure why the documentation doesn’t go into this little bit more detail. I guess it’s pretty simple though, & I’m missing the blatantly obvious as usual!

    [ Please do not bump, that’s not permitted here. ]

Viewing 3 replies - 1 through 3 (of 3 total)
  • get_group return an array with all of the fields in a group, the array has the following structure:
    [id_group][name_of_field][id_field]

    foreach($mygroup as $group) {
    if( isset($group[‘duplicated_field_name’]) ){
    for( $gruop[‘duplicated_field_name’] as $field){
    //print the permalink
    }
    }
    }

    Thread Starter matstillo

    (@matstillo)

    Hi,

    Many thanks for getting back to me!

    I’m still a little unclear how I would modify my code. Would I just use the code you have supplied instead of my code, or just replacing part of it?

    I can see that your code shows where I would print the permalink for the duplicated fields. Where & how would I print the title of the group, which I have created as a non-duplicated field?

    Many thanks for your help!

    Mat

    <?php
    	$mygroup = get_group('GroupName'); // use the Custom Group name
    	foreach($mygroup as $group) {
    ?>
    
    	<h1><?php echo $group['normal_field_name'][1]; // display a title for the group using a non-duplicated field ?></h1>
    
    	<?php
    		if( isset($group['duplicated_field_name']) ){
                      for( $gruop['duplicated_field_name'] as $field){
    	?>
    
    		<p><a href="<?php echo get_permalink($field); ?>" title="<?php echo get_the_title($field); ?>"><?php echo get_the_title($field); ?></a></p>
    
    	<?php }
              }
      ?>
    
    <?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Magic Fields: Duplicate Fields within Duplicate Groups’ is closed to new replies.