WordPress.org

Ready to get started?Download WordPress

Forums

Sorting Results (1 post)

  1. westondeboer
    Member
    Posted 4 years ago #

    The below code is for sorting of posts within a category and what not. You call it by using ?sort=name&dir=ASC at the end of a category example: http://yourwordpress.com/videos/?sort=name&dir=ASC

    <?php $sortby = $_GET['sort']; ?>
    <?php $dir = $_GET['dir']; ?>
    <?php
    $wp_query->query('cat=7&showposts=5&order='.$dir.'&orderby='.$sortby );
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <?php the_title(); ?>
    <?php endwhile; ?>

    You can see the things that you can order by at ttp://codex.wordpress.org/Template_Tags/get_posts under the $orderby section.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by westondeboer
  • This topic is not a support question
  • WordPress version: 2.7.1