• Resolved sincewelastspoke

    (@sincewelastspoke)


    Hi,

    I’d like to sort my posts by a custom field value.

    I have several ‘Posts’ and these all have a custom field called ‘orders’.

    I’d like to be able to arrange my Posts based on this integer value. Arrange in ascending order.

    Can anyone advise?
    $orders = get_post_meta($post->ID, 'orders', true);

    Currently I’m just using the standard:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    Many thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sincewelastspoke

    (@sincewelastspoke)

    OK. Found it:

    <?php
    query_posts($query_string . '&meta_key=orders&orderby=meta_value');
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    Alwyn Botha

    (@123milliseconds)

    Please mark thread as resolved so that

    – others with similar problem can see it as resolved and will read this thread for help if they have similar problem

    – people providing help see it as resolved and will not waste time reading this post.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sort Posts by Custom Field Value?’ is closed to new replies.