I’m trying to show lists of different custom post types (named "leistungen") with corresponding submodules.
So under the URL "/services" I want something like this.
Service A
- Module A1
- Module A2
- Module A3
Service B
- Module B1
- Module B2
- Module B3
I have the following setup in the UI
My current archive loop looks like this. I seem to miss a thing, but I don’t get it after hours of trying.
<?php
$outer_args = array(
'post_type' => 'leistungen',
'numberposts' => -1,
'post_parent' => 0
);
$outer_query = new WP_Query($args);
if ($outer_query->have_posts()) : ?>
<?php while ($outer_query->have_posts()) : $outer_query->the_post(); ?>
<?php $outer_id = get_the_ID(); ?>
<h2><?php the_title(); ?></h2>
<?php $issue = new WP_Query(array(
'numberposts' => -1,
'post_type' => 'leistungen',
'post_parent' => $outer_id,
)); ?>
<?php
if ($inner_query->have_posts()) ?>
<?php while ($inner_query->have_posts()) : $inner_query->the_post(); ?>
<p><?php the_title(); ?></p>
<?php endwhile; ?>
<?php $inner_query->reset_postdata(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
Currently, i neither get results nor any errors.
2
Answers
I had a couple of smaller typos in my code that I just overlooked a couple of times:
You could use
WP_Query
with combination ofget_pages
to achieve what you want.Which outputs this:
Tested and works! Let me know if you could get it to work too!