WordPress.org

Ready to get started?Download WordPress

Forums

Order posts by ID ? (6 posts)

  1. sincewelastspoke
    Member
    Posted 6 years ago #

    $readposts = get_posts('category=13');
    I am taking posts from category 13.

    How do I order these posts by their ID?

    Many Thanks,

  2. jrodgers
    Member
    Posted 6 years ago #

    change it to
    $readposts = get_posts('category=13&orderby=ID');

  3. jrodgers
    Member
    Posted 6 years ago #

  4. sincewelastspoke
    Member
    Posted 6 years ago #

    Thanks for the reply. Still not working for me :(
    Here's my code:

    <?php
    
    $readposts = get_posts('category=13&orderby=ID');
    
    ?>
    
    	<dl>
    
    	<?
        foreach($readposts as $post) : setup_postdata($post);
        ?>
    
    				<dt><a href="#"><?php the_title(); ?></a></dt>
    
    				<dd>
    					<ul>
    						<li><img src="<?php
    $supporting_image=get_post_meta( $post->ID, 'thumbnail', true );
    if (''!=$supporting_image)
    {
      echo $supporting_image;
    }
    ?>" alt="<?php the_title(); ?>" style="float:left;padding-right:20px;" />
    <?php the_content() ?></li>
    					</ul>
    				</dd>
    
        	<?php
        	endforeach;
    	?>
    
    	</dl>
    
    </div>
    
    <?
    endif;
    ?>

    It keeps it in the same order :( Any other ideas?

  5. jrodgers
    Member
    Posted 6 years ago #

    sorry about the delay, when you say it keep[s teh same order, by default posts are ordered by id form newest to oldest, how do you want them ordered?

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    If you want oldest first, add order=ASC to that. Like so:

    $readposts = get_posts('category=13&orderby=ID&order=ASC');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.