• Resolved fullflare

    (@fullflare)


    Hello everybody,

    Sorry for reposting but I’ve just seen I’ve posted my old one in a solve case which may not be good.

    I’ve just set up 2.9.1 and it seems that orderby does not work. Here is my code :

    $my_query = new WP_Query('showposts=2&cat=33&orderby=meta_value&meta_key=Date_Tri&order=desc');
    
    echo $my_query->query;
    $wpdb->show_errors()."<br />";
    
    while ($my_query->have_posts()) {
    	$my_query->the_post();
    	echo "<h2><b><u>";
    	echo get_post_meta($post->ID, 'Date_Tri', true).the_title();
    	echo "</u></b></h2>";
    	the_content();
    }

    Date_tri is some kind of text date ( 2009-02-15 for instance)

    which gives :

    showposts=2&cat=33&orderby=meta_value&meta_key=Date_Tri&order=desc

    testt2009-01-01
    Post one text ….

    Los Van Van au Bataclan le 2 mars 20102009-01-02
    Post two text ….

    Have I missed anything ?

    Thank you for your help

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Do they reverse if you change the order to asc?

    Thread Starter fullflare

    (@fullflare)

    no I’ve tried , and nothing changed

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Echo out the $my_query->request to see what the actual SQL that got generated was, see if there’s anything obviously wrong in there.

    Thread Starter fullflare

    (@fullflare)

    SELECT SQL_CALC_FOUND_ROWS wp_fv_posts.*, wp_fv_sticky.sticky_status
    FROM wp_fv_posts
    INNER JOIN wp_fv_term_relationships ON (wp_fv_posts.ID = wp_fv_term_relationships.object_id)
    INNER JOIN wp_fv_term_taxonomy ON (wp_fv_term_relationships.term_taxonomy_id = wp_fv_term_taxonomy.term_taxonomy_id)
    JOIN wp_fv_postmeta ON (wp_fv_posts.ID = wp_fv_postmeta.post_id)
    LEFT JOIN wp_fv_sticky ON wp_fv_sticky.sticky_post_id = wp_fv_posts.ID
    WHERE 1=1 AND wp_fv_term_taxonomy.taxonomy = 'category'
    AND wp_fv_term_taxonomy.term_id IN ('33')
    AND wp_fv_posts.post_type = 'post'
    AND (wp_fv_posts.post_status = 'publish' OR wp_fv_posts.post_status = 'private')
    AND wp_fv_postmeta.meta_key = 'Date_Tri'
    GROUP BY wp_fv_posts.ID
    ORDER BY (wp_fv_sticky.sticky_status = 2 AND wp_fv_sticky.sticky_status IS NOT NULL) DESC,
    	DATE_FORMAT(wp_fv_posts.post_date,'%Y-%m-%d') DESC,
    	(wp_fv_sticky.sticky_status = 1 AND wp_fv_sticky.sticky_status IS NULL) DESC,
    	DATE_FORMAT(wp_fv_posts.post_date,'%T') DESC
    	LIMIT 0, 2
    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You have some kind of plugin interfering with the query or something, because there’s no “sticky” table that I’m aware of.

    WordPress has Sticky Posts built in now, you shouldn’t need a plugin for them.

    Thread Starter fullflare

    (@fullflare)

    Well done Otto42.
    I’ve deacivated WP-Sticky plugin (I’ll just have to check side effects now ;o) )

    The query becomes
    SELECT SQL_CALC_FOUND_ROWS wp_fv_posts.* FROM wp_fv_posts INNER JOIN wp_fv_term_relationships ON (wp_fv_posts.ID = wp_fv_term_relationships.object_id) INNER JOIN wp_fv_term_taxonomy ON (wp_fv_term_relationships.term_taxonomy_id = wp_fv_term_taxonomy.term_taxonomy_id) JOIN wp_fv_postmeta ON (wp_fv_posts.ID = wp_fv_postmeta.post_id) WHERE 1=1 AND wp_fv_term_taxonomy.taxonomy = 'category' AND wp_fv_term_taxonomy.term_id IN ('33') AND wp_fv_posts.post_type = 'post' AND (wp_fv_posts.post_status = 'publish' OR wp_fv_posts.post_status = 'private') AND wp_fv_postmeta.meta_key = 'Date_Tri' GROUP BY wp_fv_posts.ID ORDER BY wp_fv_postmeta.meta_value desc LIMIT 0, 2
    So it does sort on meta !!

    Thank you very much.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_query orderby not working in 2.9.1’ is closed to new replies.