W
W
WebforSelf2021-10-06 12:59:10
WordPress
WebforSelf, 2021-10-06 12:59:10

How to exclude records of certain categories from the output?

@if (!have_posts())
    <div class="alert alert-warning">
      Ничего не найдено
    </div>
    {!! get_search_form(false) !!}
  @else
    <section class="last-series">
      <div class="archive-cont columns">
        @while (have_posts())
          @php
             the_post();
             apply_filters( 'rb_issues_footer_id', [get_the_ID()] ); // add ID
          @endphp
          @include('partials.content-grid-'.get_post_type())
        @endwhile
        {{-- Print player script --}}
        @php do_action( 'rb_issues_footer_out', apply_filters( 'rb_issues_footer_id', [] ) ); @endphp
      </div>
    </section>
  @endif


The latest entries in the Sage topic are displayed in this way.
How to exclude certain categories so that posts with them are not displayed in the latest.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan K, 2021-10-06
@ikonkov

WP_Query

A
Artem Zolin, 2021-10-06
@artzolin

Here is an example of how to exclude posts of certain categories on archive pages

add_action( 'pre_get_posts', 'exclude_category' );
function exclude_category( $query ) {
  if ( $query->is_archive() && $query->is_main_query() ) {
    $query->set( 'cat', '-1,-1347' );
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question