I don’t even know where to begin with this, so I’m just going to throw it out there. Say there is a custom post type and in it there is a wpAlchemy powered meta box with repeating fields, where in a person can add multiple attachments.Say you don’t expect or trust the user to sort the attachments themselves so you want to return the array of attachments in alphabetical order by the value title. How would you do this with the following code? (This code is within the loop of a single page)
<?php
global $attachment_repeat;
$meta = $attachment_repeat->the_meta();
?>
<?php if($attachment_repeat->have_value('docs')):?>
<ul class="attachments">
<?php while( $attachment_repeat->have_fields('docs') ) : ?>
<li>
<!--url --><a href="<?php $attachment_repeat->the_value('attachurl'); ?>" title="<?php $attachment_repeat->the_value('title'); ?>" target="_blank"><!--title --><?php $attachment_repeat->the_value('title'); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
First you should get the main array … of “docs”
$arr = $attachment_repeat->the_value('docs');if youvar_dump($arr)you will see an associative array .. you can then sort using PHP array sort functions .. maybe something like this: