WordPress.org

Ready to get started?Download WordPress

Forums

How Can I sort by Ascending Name in this Statement? (2 posts)

  1. diesel12
    Member
    Posted 4 years ago #

    I'm trying to sort the output of this statement alphabetically, I've used 'orderby'=>name and 'order'=>asc with no luck, anyone know the correct way to accomplish this?

    Any feedback appreciated!

    <?php
    $categories = get_the_category($post->ID);
    if ($categories) {
    	$category_ids = array();
    	foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
    
    	$args=array(
    		'category__in' => $category_ids,
    		'post__not_in' => array($post->ID),
    		'showposts'=>100, // Number of related posts that will be shown.
    		'orderby'=>name,
    		'order'=>asc,
    		'caller_get_posts'=>1
    	);
    $my_query = new wp_query($args);
    	if( $my_query->have_posts() ) {
    		echo '<div id="category_more_resources"> Related Information:</div><ol>';
    		while ($my_query->have_posts()) {
    			$my_query->the_post();
    		?>
    			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    		<?php
    		}
    		echo '</ol>';
    	}
    }
    ?>
  2. diesel12
    Member
    Posted 4 years ago #

    Got it working, should have been using "title" instead of "name in 'orderby' ....

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.