Hej, I’ll keep it short. I want to output this in a WP loop:
Support
Category1
-Post1
-Post2
Category2
-PostA
-PostB
-PostC
So I want to order posts by category that are located in a custom post type – support
(created thanks to Types plugin, link: ujeb.se/A4zqZ ).
I have this:
<?php
$args = array('post_type' => 'support');
$query = new WP_Query($args);
while($query -> have_posts()) : $query -> the_post(); ?>
<p><?php the_category(); ?></p>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_content(); ?></p>
<?php endwhile; ?>
My $query
stores all the necessary posts from my custom post type (support
) but I have a problem with displaying them by category. I believe I need some sort of foreach
but I can’t really figure it out. Any suggestions?
/edit/
The current display looks like this:
Support, Category1
Post1
---
Support, Category2
PostA
---
Support, Category1
Post2
etc.
Here is how you do it. You needed a foreach loop to cycle through the categories.
this work for me: