Support » Plugins and Hacks » Sorting Results

Sorting Results

  • 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']; ?>
    $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.

  • The topic ‘Sorting Results’ is closed to new replies.
Skip to toolbar