gyrus / WordPress-Developers-Custom-Fields

A plugin to provide WordPress developers with tools for managing custom fields. Check the WP repository link below for the source - GitHub currently only used for issue tracking.
http://wordpress.org/extend/plugins/developers-custom-fields/
51 stars 11 forks source link

slt_cf_get_posts_by_custom_first() is broken #10

Open gyrus opened 12 years ago

gyrus commented 12 years ago

This function is certainly broken, returning the query object instead of just the posts.

It may even be fundamentally broken - the usort() seems to just override the sorting by custom field.

Not sure whether to fix it or remove it?

tomvdv commented 12 years ago

I was just trying use this, came here to file a bug report. Obviously I vote to fix ;)

gyrus commented 12 years ago

I've had a quick look at this and I think it needs re-doing to make it work. There was one obvious error in that the $slt_cf_second_orderby and $slt_cf_second_order vars weren't declared as global in the slt_cf_order_posts() helper function.

But I think the approach is flawed. Doing it the current way, the usort() will simply erase the meta sorting. I think we need something that gets the ordering parameters right into the SQL. Almost certainly doable, but it's not something that's urgent for me. I imagine it could be easily done "alongside" the plugin by hooking in the query.

I'm putting the code on GitHub now, so maybe someone else can contribute a working version of the function?