order posts by custom field

i’m using this query

$numposts = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=5&showposts='.$numposts.'&paged=' . $paged); 

how to order the posts by custom field?

Related posts

Leave a Reply

2 comments

  1. how about?

    $customfield = "MyCustomFieldName";
    $numposts = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=5&showposts='.$numposts.'&paged='.$paged.'&meta_key='.$customfield.'&
    orderby=meta_value&order=DESC');
    

    or instead of creating a new variable just to hold the custom field just add it straight into the query..

    query_posts('cat=5&showposts='.$numposts.'&paged='.$paged.'&meta_key=mycustomfield&
    orderby=meta_value&order=DESC')