WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sort Posts by Custom Field Value? (3 posts)

  1. sincewelastspoke
    Member
    Posted 3 years ago #

    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

  2. sincewelastspoke
    Member
    Posted 3 years ago #

    OK. Found it:

    <?php
    query_posts($query_string . '&meta_key=orders&orderby=meta_value');
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>
  3. 123milliseconds
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.