troubleshooting Question

Sorting custom posts by alphabetical order

Avatar of rjunk
rjunk asked on
PHPWordPressContent Management
3 Comments1 Solution493 ViewsLast Modified:
I have built a WP site for a small non-profit.  

On the "Who We Are" page, there are different lists of names: staff members, advisory boards, etc.  

I have set this page up as a series of custom posts.

The client would like to order these lists alphabetically by last name.

I did some research and found a way to customize the loop that should alphabatize by last name.  

However, I can only get the loop to output one name: it is not displaying all the names in the list.  

My questions are: what am I missing?  And, is there a more elegant way to do this?

The page in question is here:
The test list is towards the bottom of the page; it is called "Friends Alpha Test".

The code I used is below.

Thank you very much!

<h4>Friends Alpha Test</h4>
            $lastname = array();
$posts = get_posts( array('post_type' => 'people', 'whoweare' => 'friends', 'numberposts'  => 100) );

foreach( $posts as $key => $post ) {

      $lastname[$key] = array_pop( explode( ' ', $post->post_title ) );
array_multisort( $lastname, SORT_ASC, $posts );
                   if ( have_posts() ) : while ( have_posts() ) : the_post();
             <li><?php the_title(); ?></li>
             <li><?php the_content(); ?></li>
            <?php endwhile; endif; wp_reset_query(); ?>

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros