cerstrand_mace Posted April 17, 2013 Share Posted April 17, 2013 I want to order my query by one of my custom field values. That custom field value is a repeater field inside a regular custom field. However, the problem is that my query is set to only show pages from a certain template, wich is done by the meta_key and meta_value attributes. As far as I get it the meta_key and meta_value should also be used to order my query. How can I do both? My query looks like this: query_posts(array( 'meta_key' => '_wp_page_template', 'meta_value' => 'template-kursny.php', 'showposts' => -1, 'post_type' => 'page', )); I've tried to google this for a while now and I've found similar cases but haven't found a working solution yet. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 17, 2013 Share Posted April 17, 2013 You want to use those values to sort the data? Does the query_posts function have a way to specify sort criteria? If not, if it returns an array of posts, then you can use a custom sort function to sort the array. Link to comment Share on other sites More sharing options...
cerstrand_mace Posted April 18, 2013 Author Share Posted April 18, 2013 You want to use those values to sort the data? Does the query_posts function have a way to specify sort criteria? If not, if it returns an array of posts, then you can use a custom sort function to sort the array. How would such a custom sort function look like? The values I wan't to sort this array by are the ones I have in a repeater-field, a date to be specific. The subfield name is "slutdatum". Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2013 Share Posted April 18, 2013 You use usort, uasort, or uksort to sort an array using a user-defined function: http://www.php.net/manual/en/function.usort.php You just need to write a function that takes 2 values, which would be 2 elements in your array, and you return a value less than or greater than 0 to indicate which element should come first in the array. If it returns 0 then that means the elements are equal. There are a few examples on that manual page, and several comments at the bottom. Link to comment Share on other sites More sharing options...
cerstrand_mace Posted May 6, 2013 Author Share Posted May 6, 2013 I solved this problem by putting all my values in a table instead, and then using a jquery tablesorter to order the values. Works like a charm! Thanks anyway! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now