WordPress.org

Ready to get started?Download WordPress

Forums

sorting all posts in alphabetical order (1 post)

  1. saddie.dean
    Member
    Posted 2 years ago #

    Hi.
    i am trying to sort my multiple category's posts in alphabetical order on a page. I am using following code in my custom created page (ilc.php) and 29,28,27,26,25,24,23,22,21,20,19,18,16,15,14,13,12,11,10,9,8 are the category ids whose posts I want on the page:

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('cat=29,28,27,26,25,24,23,22,21,20,19,18,16,15,14,13,12,11,10,9,8&showposts=10'.'&paged='.$paged);?>
    <?php global $more; $more = 0; ?>
    <?php while ($wp_query->have_posts()): $wp_query->the_post();?>
    <?php include('inst-post.php');?>
    <?php endwhile; ?>
    
    <?php //...pagination code?>

    the included page "inst-post.php" contains following code:

    <table width="100%" cellspacing="0" cellpadding="3" style="border-collapse:collapse; float: left; padding-left: 0px;" class="clear instructor" id="newtbl">
      <tr>
        <td width="25%" class="border"><h4 class="inscat"><?php $catto = get_the_category(); echo $catto[0]->cat_name; ?> </h4></td>
        <td width="25%" class="border"><h5 class="inscrs"><a style="color:#000000;font-weight:bold; text-decoration:none;" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php _e('Permanent Link to', 'cp'); ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h5></td>
        <td width="50%" class="border"><span class="insdsc"> <?php echo get_post_meta($post->ID, overview, true); ?></span></td>
      </tr>
    </table>

    Now, I am getting the posts in a table with category name on the left, post title in the middle(with a permalink) & description on the right of the table. I tried orderby=name, orderby title

    $wp_query->query('cat=29,28,27,26,25,24,23,22,21,20,19,18,16,15,14,13,12,11,10,9,8&orderby=name&order=ASC&showposts=10'.'&paged='.$paged);?>

    $wp_query->query('cat=29,28,27,26,25,24,23,22,21,20,19,18,16,15,14,13,12,11,10,9,8&orderby=title&order=ASC&showposts=10'.'&paged='.$paged);?>

    etc, but they also dont work. On the result page the posts come in the table but they are ordered by their ID ie. whatever orderby I am using it doesnt work for me :( the posts show up according to the category-id order.

    Kindly help me in sorting the posts.

Topic Closed

This topic has been closed to new replies.