Hi vandelay,
the problem you describe is excactly what I stumbled on as well. While looking for a solution I came across your post.
I tried to adapt your code from above, but I think I don“t get it.
Here is code I am using right now, where the sorting order of the field is still wrong:
$lifestyle_data_fields = get_fields($post->ID);
// Here I need to get the fields and order them like they are ordered in the WP-Backend for a lifestyle_data post (or like they are ordered in the field-group, which is the same)
foreach ($lifestyle_data_fields as $name => $values) {
if ($values) {
foreach ($values as $value) {
...
Now I tried to adapt your code to match mine:
$lifestyle_data_fields = get_fields($post->ID);
function array_orderby()
{
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array();
foreach ($data as $key => $row)
$tmp[$key] = $row[$field];
$args[$n] = $tmp;
}
}
$args[] = &$data;
call_user_func_array('array_multisort', $args);
return array_pop($args);
}
$lifestyle_data_fields = array_orderby( $lifestyle_data_fields, 'menu_order', SORT_ASC);
foreach ($lifestyle_data_fields as $name => $values) {
if ($values) {
foreach ($values as $value) {
...
But I get an error message “Warning: Illegal string offset ‘menu_order’ ” and the sorting order is not changed.
Can you or somebody else help me to get this sorted?
Thanks in advance for any input,
Hendrik