I want to loop through categories and display the post's title under each category dropdown. Clicking the post name from the dropdown will display the post content in a tab pane in WordPress. Can someone please suggest a code solution.
<?php
$args = array(
'taxonomy' => 'types',
'orderby' => 'name',
'order' => 'ASC'
);
$cats = get_categories($args);
$c = 1;
foreach($cats as $cat) {
?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle <?=($c == 1) ? 'active' : ''?>" href="#<?php echo $cat->name; ?>" role="button" data-toggle="tab" aria-haspopup="true" aria-expanded="false"><?php echo $cat->name; ?></a>
<div class="dropdown-menu">
<?php
$cat_slug = $category->slug;
$the_query = new WP_Query(array(
'post_type' => 'project',
'category_name' => $cat_slug
));
while($the_query->have_posts()){
$the_query->the_post();
?>
<a class="dropdown-item" href="#<?php the_ID(); ?>" data-toggle="tab"><?php the_title(); ?></a>
<?php }
wp_reset_postdata();
?>
</div>
</li>
<?php
$c++;
}
wp_reset_postdata();
?>