WordPress.org

Ready to get started?Download WordPress

Forums

orderby=name not working in get_posts (3 posts)

  1. Brad Thomason
    Member
    Posted 4 years ago #

    Using get_posts, ordering by slug is listed as an option in the documentation by calling orderby=name, but this doesn't seem to have any affect on the loop.

    Is there another way you can order pages by slug instead of title or ID? I don't see it as an option using query_posts. Any ideas?

    Here's the code I'm using:

    <?php
    global $post;
    $pageID = $post->ID;
    $myposts = get_posts('post_parent='.$pageID.'&numberposts=-1&post_type=page&orderby=name&order=ASC');
     foreach($myposts as $post) :
       setup_postdata($post);
    ?>
    
    <div class="post column" id="post-<?php the_ID(); ?>">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php
    if ( has_post_thumbnail() ) {
    	the_post_thumbnail( 'thumbnail' );
    } else {
    	postimage( 'thumbnail' );
    }
    ?></a>
    <h4 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    
    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    </div> <!-- /.post.column -->
    
    <?php endforeach; ?>

    Thanks!

  2. vanzvik
    Member
    Posted 3 years ago #

    I am having the exact same problem :(

  3. rhwinter
    Member
    Posted 3 years ago #

    try using "title" instead of "name".
    so for example, Brad, your code would become:

    $myposts = get_posts('post_parent='.$pageID.'&numberposts=-1&post_type=page&orderby=title&order=ASC');

    it seems to work for me.

Topic Closed

This topic has been closed to new replies.

About this Topic