NB: I don't have enough reputation to ask the question directly on the post mentioned.
I've used some code from 1: Get all categories and posts in those categories
It lists all the Categories with the Posts listed inside those Categories, but I'm having trouble setting the orderby ...
Specifically the Revisit answer here
<?php
$args = array(
'posts_per_page' => -1
);
$query = new WP_Query($args);
$q = array();
while ( $query->have_posts() ) {
$query->the_post();
$a = '<a href="'. get_permalink() .'">' . get_the_title() .'</a>';
$categories = get_the_category();
foreach ( $categories as $key=>$category ) {
$b = '<h2><a href="' . get_category_link( $category ) . '">' . $category->name . '</a></h2>';
}
$q[$b][] = $a; // Create an array with the category names and post titles
}
/* Restore original Post Data */
wp_reset_postdata();
foreach ($q as $key=>$values) {
echo $key;
echo '<ul>';
foreach ($values as $value){
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
?>
What i'm trying to do is add ordering by Category Title, then within that category orderby Post Title.
I can add it in the intial $args on line 1
$args = array(
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
);
This sorts the categories in order of the title of the posts contained in that category.
I'm trying to get the Categories in ASC order, then the posts within that category in ASC order but I can't figure out how to order them both.
Be very grateful for any advice