Site icon Hip-Hop Website Design and Development

How one can group solely VISIBLE posts?

Good afternoon

With the assistance of a fellow consumer right here I’m lastly capable of show all posts on a single web page with the respective submit month as a divider between the teams.

So it seems to be one thing like this:

February 2021
----------------- 
submit 5 
submit 4


January 2021
------------------ 
Submit 3 
Submit 2 
Submit 1


...and so forth...

To date so good.
However I’ve an extra "filter" on that web page, which exhibits or hides posts on click on. e.g. you are capable of filter by submit writer and if a submit does dot match the filter the submit is being hidden with the addition of a "style=display:none" on its container.

Massive query: How do I show the divider provided that there are seen posts for that divider group?

<?php
    $wpb_all_query = new WP_Query( [
        'post_type'=>'post',
        'post_status'=>'publish',
        'posts_per_page'=> -1,
        'orderby' => 'date',
        'order' => 'DESC'
    ] );

    $dividers = [];
?>

<?php if ( $wpb_all_query->have_posts() ) : ?>

    <div id="list_allposts">
        <?php whereas ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>

            <?php $post_date = get_the_date( 'F Y' ); ?>
            <?php if ( !in_array( $post_date, $dividers ) ): ?>
                <?php $dividers[] = $post_date; ?>
                <div class="divider">
                    <?= $post_date; ?>
                </div>
            <?php endif ?>

            <!-- Submit code right here -->

        <?php endwhile; ?>
    </div>

<?php endif; wp_reset_postdata(); ?>

PS: For the time being I’m simply hiding the divider as quickly as there may be an lively filter. However perhaps there’s a higher resolution in order that we will have dividers ALTHOUGH there may be an lively filter. Would make the web page simply MORE PERFECT..