Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to get ordered all my posts with multiple cutom fields (WordPress 3).

Exemple, I've 2 custom couple meta_key/meta_value : " order_submenuexpositions / numeric " " display_submenuexpositions / boolean "

I tried like this, but the result it's not 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 can i do it ?

thank you !

share|improve this question
add comment

1 Answer

You can use meta_query to get only posts with display_submenuexpositions = true and order them by order_submenuexpositions.

$args = array(
    'orderby' => 'meta_value',
    'meta_key' => 'order_submenuexpositions',
    'meta_query' => array(
        array(
            'key' => 'display_submenuexpositions',
            'value' => 'true',
            'compare' => 'LIKE'
        )
    )
);
$query_posts( $args );
share|improve this answer
    
@t31os: thanks! –  Bainternet Mar 23 '11 at 18:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.