Quite a pesky problem here. I've taken over a site that contains multiple information, serialised, within a custom field. For example:
if ($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post(); $ids = get_post_custom( get_the_ID() ); print_r($product_custom_fields['item_data']); endwhile; endif;
Would return something along the lines of:
I'd like to be able to run a query that orders all of these items by 'regular_price' but cannot determine the best way to achieve this.
I currently have decided to run a preliminary query:
$new_query = new WP_Query( $args ); if ($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post(); $ids = get_the_ID(); endwhile; endif;
This gets all the correct items into the array $ids. I can then run a function which will sort these IDs into the order I want, by mucking about with the serialized data. I can then run:
query_posts(array('post__in' => $ids) );
Which will filter my main results by the ids and order I have set up.
The trouble being, this queries the posts twice, and potentially is a bit longwinded.
If anyone can suggest a more succinct method, maybe with direct SQL injection into the query, it would be much appreciated.