C
C
Concencuc2021-10-14 17:50:12
WordPress
Concencuc, 2021-10-14 17:50:12

How to display all categories of current posts?

6168424bea5ea343636755.jpeg
I have a search. And wp query filters posts by search result.

$posts = new WP_Query(array(
  'post_type' => 'post',
  'posts_per_page' => 9999,
  's' => $_GET["s"],
  )
);

Now the categories of posts are displayed in this way
$catArray = array(
              'taxonomy'     => 'post_category',
              'type'         => 'post',
              'hide_empty'  => true,
          );

          $categories = get_categories( $catArray );

          foreach ( $categories as $cat ) { 
            $catLink = get_category_link($cat->cat_ID);

            $active = '';
            if ($catLink == $pagelink) {
              $active = ' active';
            }
            ?>
              <li>
                <a class="category<?php echo $active; ?>" href="<?php echo get_category_link($cat->cat_ID); ?>">
                  <span class="radio-el"></span>
                  <span class="title"><?php echo $cat->name ?></span>
                  <span class="count"><?php echo $cat->count; ?></span>
                </a>
              </li>
          <?php } ?>

How to display categories of only those posts that appeared in the search result?
That is, 2 posts were displayed, in the "All" supercategory, I have it displayed like this - 2.
But below all the categories of the site are displayed, and the number of posts that are in these categories.
Tell me the solution please

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question