Sort order in get_posts
I've created a custom template for a client. This is going to be a multilingual site setup on a Multisite install.
As you can see under each category letter, the posts start out in alphabetical order but "M" and "O" are all out of whack.
If you click through onto those categories, using the alphabet bar at the top, those posts are in alphabetical order.
Both pages are using the same code, so I've no idea what I'm doing wrong. I have a feeling I have a query conflict somewhere but I can't find it. Here's the code that does the sorting:
section class="atozlist"
?php
$newargs = array(
'child_of' = $catID,
'order' = 'ASC'
);
$categories = get_categories($newargs);
foreach ($categories as $category) {
echo 'h2'.$category-name.'/h2';
echo 'ul';
$titleArgs = array(
'cat' = $category-term_id,
'order_by' = 'title',
'order' = 'ASC'
);
foreach (get_posts($titleArgs) as $post) {
setup_postdata( $post );
echo 'lia href="'.get_permalink($post-ID).'"'.get_the_title().'/a/li';
}
wp_reset_postdata();
echo '/ul';
}
?
/section
I'm unsure about the implementation of setup_postdata($post)
, though I used this as a template. I'm also unsure if I've implemented wp_reset_postdata()
correctly.
Anyone any ideas?
Topic wp-reset-postdata get-posts query Wordpress
Category Web