Display category and Subcategory with Post

PHOTO EMBED

Wed Aug 02 2023 13:03:12 GMT+0000 (Coordinated Universal Time)

Saved by @gshailesh27

<?php
$taxonomies = get_terms(array(
    'taxonomy' => 'mail_category',
    'hide_empty' => false,
    'parent' => 0,
));
$i = 1;
    foreach ($taxonomies as $parent) { ?>
        <div id="accord_<?php echo $i; ?>" class="accordionBox">
                        <div class="accordionHead active">
                        <?php echo $parent->name; ?>
                        </div>
                        <div class="accordionMatter">
      <?php  $children = get_terms(array(
            'taxonomy' => 'mail_category',
            'parent' => $parent->term_id,
            'hide_empty' => false,
        ));
        foreach ($children as $child) { ?>

            <li class="active"><span><?php echo  $child->name; ?></span>
                                    <div class="filterSliderCont">
                                        <div class="filterSlider swiper">
                                            <div class="swiper-wrapper">
 
<?php
$args = [
    "post_type" => "journal", // Replace 'your_post_type' with the actual name of your post type
    "posts_per_page" => -1, // Retrieve all posts
    "order" => "ASC",
    "tax_query" => [
        [
            "taxonomy" => "mail_category",
            "field" => "slug",
            "terms" => $child->slug,
        ],
    ],
];
 
$query = new WP_Query($args);
 
if ($query->have_posts()) :
    while ($query->have_posts()) : $query->the_post(); ?>	

<div class="filterSlide swiper-slide">
                                                    <div class="boxData">
                                                        <div class="boxMatter">
                                                            <p>
                                                               <?php echo the_title(); ?>
                                                            </p>
                                                        </div>
                                                        <div class="row justify-content-between align-items-center">
                                                            <div class="col-auto authorName">
                                                                <?php echo get_author_name(); ?>
                                                            </div>
                                                            <div class="col-auto authorName">
                                                                <a href="<?php echo the_permalink(); ?>" class="yellowBtn">
                                                                    View Details
                                                                </a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
 
                    <?php endwhile;
                    wp_reset_postdata();
                else:
                    // Display "no data found" message
                    echo '<p class="ndfmsg" style="text-align: center;">No data found.</p>';
                endif;
                ?>		
 </div>
                                        </div>
                                    </div>
                                </li>
                                <?php } ?>
                                </ul>
                        </div>
                    </div>
<?php $i++;

} ?>
content_copyCOPY