Wrap an X amount of taxonomy posts in a separate Row in WordPress

I am trying to create a slider with taxonomy post categories and its Posts so the structure will look like this

Row 1
    First Category Title
      First category Post Title Goes Here
    Second Category Title
      Second category Post Title Goes Here
Row 2
    Third Category Title
      Third category Post Title Goes Here
    Fourth Category Title
      Fourth category Post Title Goes Here

So what i tried currently for getting the taxonomy category and its posts is teh below snippet

<div class="clientsListWrapper">
                <ul>
                    <?php 
                        $post_type = 'clients';
                        $taxonomies = get_object_taxonomies(array( 'post_type' => $post_type));
                        foreach($taxonomies as $taxonomy) :
                            $terms = get_terms($taxonomy);
                            foreach($terms as $term) : ?>
                              <li><a><?php echo $term->name; ?></a>
                                <?php
                                $args = array(
                                    'post_type' => $post_type,
                                    'posts_per_page' => -1,  //show all posts
                                    'tax_query' => array(
                                        array(
                                            'taxonomy' => $taxonomy,
                                            'field' => 'slug',
                                            'terms' => $term->slug,
                                        )
                                    )
                                );
                                $posts = new WP_Query($args);
                                if($posts->have_posts()): ?>
                                <ul>
                                <?php  while($posts->have_posts() ) : $posts->the_post(); ?>
                                    <li><a><?php  echo get_the_title(); ?></a></li>
                                <?php endwhile; endif; ?>
                                </ul></li>
                            <?php endforeach;
                        endforeach; 
                    ?>
                </ul>
            </div>

But could not manage to create the separating part with a li or div so i wrap every row in a div or li.

ANy ideas how i achieve this?

Read more here: Wrap an X amount of taxonomy posts in a separate Row in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *