Skip to content

Instantly share code, notes, and snippets.

@kirstenkeister
Created February 23, 2012 22:22
Show Gist options
  • Select an option

  • Save kirstenkeister/1895369 to your computer and use it in GitHub Desktop.

Select an option

Save kirstenkeister/1895369 to your computer and use it in GitHub Desktop.
Repeating fields for project pages
<?php
global $project_mb;
$project_mb->the_meta();
$i = 0;
while($project_mb->have_fields('links') || $project_mb->have_fields('paststaff') ) {
if($i == 0)
{ ?>
<div id="info-staff" class="column left">
<h2 class="column-title">Participating MITH Staff</h2>
<ul>
<?php } // endif
$staffname = $project_mb->get_the_value('projectstaff');
$paststaffname = $project_mb->get_the_value('past-projectstaff'); ?>
<li><a href="<?php echo get_permalink($staffname); ?>" class="c-staff-link"><?php echo get_the_title($staffname); ?></a></li>
<li><a href="<?php echo get_permalink($paststaffname); ?>" class="p-staff-link"><?php echo get_the_title($paststaffname); ?></a></li>
<?php $i++; } // endwhile
if ($i > 0 ) { ?>
</ul>
</div>
<?php } // endif ?>
<!-- /project-staff -->
@kirstenkeister
Copy link
Author

Yeah, I generally try to do the open/close thing unless it's misbehaving. Sometimes I've had the information not show up properly when I do it with regular HTML, but it's probably fixable without echoing if I kept at it. Regardless, this is a good call and I will try to make open/close php tags standard unless absolutely necessary.

@jdickie
Copy link

jdickie commented Feb 29, 2012

Did you already use the the_field() command to switch fields inside of a while loop? Looking at the WP_Alchemy website, it seems that they want you to set it up so that you pull the data once (do the while $project->have_fields() one time) then switch between data fields by either the_field or the_value calls.

If that isn't working, what I would suggest is that we take a look at your data model and see if it's not satisfying what you're asking it. Sometimes the issue with my stuff is that I design the data for one purpose, then find that I query for something totally different and have to go back and re-design the database. It's painful, but pays off in the long run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment