I'm creating a website for a book publishing company. They've books in multiple different languages and want to display some details for each language. To retrieve all the necessary information for each language, I do the following:
<div class="col-lg-3" align="center">
<?php
$fields = get_field_objects();
if ($fields):
foreach ($fields as $name => $field):
if (stripos($name, 'isbn') !== false) : ?>
<?php $lang = substr($field['name'], strpos($field['name'], "_")); ?>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1<?php echo $lang ?>">Deutsch/<?php echo substr($field['label'], strpos($field['label'], " ") + 1); ?></a>
</h4>
</div>
<div id="collapse1<?php echo $lang ?>" class="panel-collapse collapse">
<div class="panel-body">
// ... get all neccessary information ...
</div>
</div>
</div>
</div>
<?php endif;
endforeach;
endif; ?>
</div>
Now my problem is, that if somebody creates a book, forgets to add a language and wants to add it after the book has been saved to the database, the alphabetical order is not correct anymore. Therefore I'd like to add a sorting function for the $fields array.
sort($fields) doesn't work since after doing this, everything is blank.
Here's a screenshot of how the output looks like.
And sometimes, the order is wrong (e.g. Deutsch/English appears on the bottom). So I'll have to sort the part where I add the second language (next to German). The part where I add this is here:
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1<?php echo $lang ?>">Deutsch/<?php echo substr($field['label'], strpos($field['label'], " ") + 1); ?></a>
</h4>
Does anyone have any ideas? Please let me know if code is missing!
P.S. the plugin I use is "Advanced-Custom-Fields" and the functions like e.g. "get_field_objects()" come with that plugin!