I'm try to get the output of this post type to order by the staff name alphabetically and I can't seem to figure out if needs to be within the beginning array()
or if I been do something within the foreach()
loop.
Here's my constructed loop:
<?php
$mypost = array('post_type' => 'staff', 'posts_per_page' => 20, 'orderby' => 'staff-name',
'order' => 'ASC' );
$loop = new WP_Query( $mypost );
?>
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<?php $items = get_post_meta( $post->ID, 'elements', true );
foreach( $items as $i){
echo'<li>
<a href=" '. get_permalink() .' ">' . $i['staff-name'] . '</a>
</li>
';
}
?>
<?php endwhile; wp_reset_query(); ?>
The staff-name
field hold the first and last name of the staff member, but for some reason it doesn't look like it's sorting them alphabetically correctly.
I do notice that if I change it from ASC
to DESC
it does change the order of the output, but it's not alphabetized. It's almost like it's ignoring the field staff-name
and ordering it by the post ID instead.
$mypost = array('post_type' => 'staff', 'posts_per_page' => 20, 'meta_key' => 'staff-name', 'orderby' => 'staff-name', 'order' => 'ASC' );