• A list of posts from one category is being sorted by id. I want to change this to be sorted by a custom field – SeasonDateFrom1. Your help would be much appreciated.

    Original Code:
    query_posts(‘post_status=publish&category_name=world-wide-yacht-rallies&posts_per_page=50&offset=0&orderby=id&order=ASC’);

    my unsuccessful idea:
    post_status=publish&category_name=world-wide-yacht-rallies&posts_per_page=50&offset=0′ . ‘&meta_key=seasondatefrom1’ . ‘&orderby=meta_value_num,date&order=ASC’

    SQL output :
    REQUEST: SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (7) ) AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’) AND (wp_postmeta.meta_key = ‘seasondatefrom1’ ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC LIMIT 0, 50

  • The topic ‘Order by custom date field not working’ is closed to new replies.