[insert_php]
$args = array(
‘posts_per_page’ => -1
);
$query = new WP_Query($args);
$q = array();
while ( $query->have_posts() ) {
$query->the_post();
$a = ‘‘ . get_the_title() .’‘;
$categories = get_the_category();
foreach ( $categories as $key=>$category ) {
$b = ‘
‘ . $category->name . ‘
‘;
}
$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 ‘
- ‘;
- ‘ . $value . ‘
foreach ($values as $value){
echo ‘
‘;
}
echo ‘
‘;
}
[/insert_php]