Images output in wrong order...

0

I have a pod item with a column type file, this column can have multiple images. I need this column to send me back the images in the order they are placed in the column. They however seem to come back sorted on the id. How can i get my returned $value to show up unsorted. If i go into the pod admin, everything shows up in the correctly placed order, so i know its happening sometime before display.

Any help would be appreciated. Thanks.

asked Jan 30 at 8:19

Eric Basti

1

add comment
enter at least 15 characters

4 Answers

0

Bring $value into an array and then write a function to perform a uasort() of $value on the post_date key. You can then loop through $value with a foreach to output the items in the order you wish.

answered Jan 31 at 4:46

chris.pilko

889

add comment
enter at least 15 characters
0

Thanks for the suggestion, I'll see what I can make this do for me. It just seems so odd that they $value array returned from pods comes presorted by ID. You would think it would be easier to just send it back to me as I put it in.

answered Feb 1 at 12:30

Eric Basti

1

add comment
enter at least 15 characters
0

Actually, we are using the "weight" column to track the order of file / pick relationships as they're saved, but the SELECT we get for the "real" data returns it ordered by insert ID. So actually, we're using a ID IN(1,3,5,2,6) WHERE clause, where as 1,3,5,2,6 is the order of the IDs actually saved in the UI, but MySQL doesn't follow that ordering when returned. I'll look into a quick fix, feel free to check into MySQL ORDER BY and see what you might be able to come up with too and I'll consider that for 1.12.3

answered Feb 1 at 11:40

sc0ttkclark

2936

I modified /classes/Pod.php starting at line 293 (just added a line) see block below. It's not tested a ton, but returns the file attachments in the proper order, when you're not forcing a different $orderby. <code> // WP page, post, or attachment elseif ('wp_page' == $table || 'wp_post' == $table || 'file' == $table) { $orderby = empty($orderby) ? "ORDER BY field(ID, $tbl_row_ids)" : ''; $result = pod_query("SELECT * FROM `$wpdb->posts` WHERE `ID` IN ($tbl_row_ids) $orderby"); } </code> – weskoop May 18 at 11:28
I modified /classes/Pod.php starting at line 293 (just added a line) see block below. It's not tested a ton, but returns the file attachments in the proper order, when you're not forcing a different $orderby. <pre> // WP page, post, or attachment elseif ('wp_page' == $table || 'wp_post' == $table || 'file' == $table) { $orderby = empty($orderby) ? "ORDER BY field(ID, $tbl_row_ids)" : ''; $result = pod_query("SELECT * FROM `$wpdb->posts` WHERE `ID` IN ($tbl_row_ids) $orderby"); } </pre> – weskoop May 18 at 11:29
Sorry double post, couldn't figure out the code block. – weskoop May 18 at 11:29
add comment
enter at least 15 characters
0

added this to the end of the function rel_lookup to get it to send the array in the weighted order:

$pieces = explode(",", $tbl_row_ids); // take our correct order string and turn it into a usable array
array_multisort($pieces,$data);  // take our resulted data and sort it in order based on $pieces since its currently ordered by 'ID'
    }
else {
    $data = $result;
}
    return $data;
}

answered Feb 2 at 10:03

Eric Basti

1

add comment
enter at least 15 characters