I must get purchased my posts with multiple cutom fields (Wordpress 3). Exemple, I have 2 custom couple meta_key/meta_value :

" order_submenuexpositions / numeric "
" display_submenuexpositions / boolean "

I attempted such as this, however the result it isn't orderer by meta_value from "order_submenuexpositions" meta_key :

SELECT * FROM wp_posts 
LEFT JOIN wp_postmeta wpostmetaOrder ON ( wp_posts.ID = wpostmetaOrder.post_id AND wpostmetaOrder.meta_key = 'order_submenuexpositions' )
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id 
LEFT JOIN wp_term_relationships wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE wp_postmeta.meta_key = 'display_submenuexpositions'
AND wp_postmeta.meta_value = 'true'
AND wp_posts.post_status = 'publish' 
AND wp_posts.post_type = 'post' 
AND wp_term_taxonomy.taxonomy = 'category'
ORDER BY wpostmetaOrder.meta_value ASC,wp_postmeta.meta_value ASC

how do i get it done ?

thanks !


ok resolved, it is because meta_value sql area type is longtext and that i attempted to buy on integer value..it's does not work.you need to cast type on integer, such as this :

SELECT * FROM wp_posts 
LEFT JOIN wp_postmeta wpostmetaOrder ON ( wp_posts.ID = wpostmetaOrder.post_id AND wpostmetaOrder.meta_key = 'order_submenuexpositions' )
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id 
LEFT JOIN wp_term_relationships wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE wp_postmeta.meta_key = 'display_submenuexpositions'
  AND wp_postmeta.meta_value = 'true'
  AND wp_posts.post_status = 'publish' 
  AND wp_posts.post_type = 'post' 
  AND wp_term_taxonomy.taxonomy = 'category'
ORDER BY CAST(wpostmetaOrder.meta_value AS SIGNED) ASC,wp_postmeta.meta_value ASC`