K
K
Keit2652020-07-08 17:36:48
WordPress
Keit265, 2020-07-08 17:36:48

How to make a search using a filter on all pages?

The filter works on the principle of searching for identical classes. The filter from value takes the value and outputs all programs with the same class as the value was. Now I have more than 550 programs, so the page loading takes a very long time and I decided to make pagination with the output of 11 programs each so that the page loads faster. But I ran into a problem that the filter does not search from all pages of the program, but only from the one on which it is located.
If you are on page 3 of programs, then the filter will search for programs only from page 3, and not from all 50.
So the QUESTION arose: how to make it filter not from one page you are on, but from all at once, so that all programs were filtered.
Thank you very much in advance for at least trying to help me!)
So, there is this code:

Page code

<!-- Простой filter -->
<div class="simple-filter button-group">
  <div class="simple-filter_item button-group filters">
    <p class="rus">Уровень подготовки</p>
    <?php
    $categories = get_terms('level', 'orderby=name&hide_empty=0');
    if($categories){
      echo '<select id="level1"><option value="card-item">Любой</option>';
      foreach ($categories as $cat){
        echo "<option <b>value='level-{$cat->term_id}</b>'>{$cat->name}</option>";
      }
      echo '</select>';
    }
    ?>
  </div>
  <div class="simple-filter_item">
    <p>Направление образования</p>
    <?php
      $categories = get_terms('direction', 'orderby=name&hide_empty=0');
      if($categories){
        echo '<select id="direction1"><option value="card-item">Любой</option>';
        foreach ($categories as $cat){
          echo "<option <b>value='direction-{$cat->term_id}</b>'>{$cat->name}</option>";
        }
        echo '</select>';
      }
    ?>
  </div>
  <!-- Расширенный filter -->
    <div class="advanced-filter_item filter-disactive simple-filter_item">
      <p>Университет</p>
      <?php
      $categories = get_terms('university', 'orderby=name&hide_empty=0');
      if($categories){
        echo '<select id="universities"><option value="card-item">Любой</option>';
        foreach ($categories as $cat){
          echo "<option <b>value='university-{$cat->term_id}</b>'>{$cat->name}</option>";
        }
        echo '</select>';
      }
      ?>
    </div>
    <div class="advanced-filter_item filter-disactive simple-filter_item">
      <p class="rus">Язык обучения</p>
      <p class="eng hide">language of education</p>
      <?php
      $categories = get_terms('language', 'orderby=name&hide_empty=0');
      if($categories){
        echo '<select id="language"><option value="card-item">Любой</option>';
        foreach ($categories as $cat){
          echo "<option <b>value='language-{$cat->term_id}</b>'>{$cat->name}</option>";
        }
        echo '</select>';
      }
      ?>
    </div>
    <div class="advanced-filter_item filter-disactive simple-filter_item">
      <p class="rus">Программа</p>
      <p class="eng hide">Program</p>
      <?php
      $categories = get_terms('program', 'orderby=name&hide_empty=0');
      if($categories){
        echo '<select id="program"><option value="card-item">Любая</option>';
        foreach ($categories as $cat){
          echo "<option <b>value='program-{$cat->term_id}</b>'>{$cat->name}</option>";
        }
        echo '</select>';
      }
      ?>
    </div>
    <div class="filter-button filter-disactive">
      <div class="simple-btn">
        <button type="button" class="btn_access" onclick="applyFilters()">Подобрать</button>
      </div>
      <div class="advanced-more-filter simple-more-filter more-filter">
        <img src="<?php echo get_template_directory_uri() ?>/includes/img/setting.png" alt="setting">
        <span>Простой фильтр</span>
      </div>
    </div>
  <!-- Расширенный filter (end) -->
  <div class="filter-button">
    <div class="simple-btn">
      <button type="button" class="btn_access" onclick="applyFilters()">Подобрать</button>
    </div>
    <div class="simple-more-filter more-filter">
      <img src="<?php echo get_template_directory_uri() ?>/includes/img/setting.png" alt="setting">
      <span>Расширенный фильтр</span>
    </div>
  </div>
</div>
/code>
<code lang="javascript">
// Фильтрация программ
    function applyFilters() {
    	// Инициализация классов
     	var direction1 = $("#direction1").val();
      var level1 = $("#level1").val();
      var universities = $("#universities").val();
      var language = $("#language").val();
      var program = $("#program").val();
      // Создания селектора
      var selector = "#card-wrapper-first ." + direction1 + "." + level1 + "." + program + "." + language + "." + universities;

      // Появление нового запроса
      $('#card-wrapper-first .card-item').hide();
      $(selector).show();
    }
</code>
<spoiler title="Программа">
<code lang="php">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
    'post_type' => 'program-card',
    'posts_per_page' => 11,
    'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();?>

<div class="card-item level-<?php $term_list = wp_get_post_terms( $post->ID, 'level', array( 'fields' => 'ids' ) );
echo reset( $term_list ); ?> direction-<?php $term_list = wp_get_post_terms( $post->ID, 'direction', array( 'fields' => 'ids' ) );
echo reset( $term_list ); ?> university-<?php $term_list = wp_get_post_terms( $post->ID, 'university', array( 'fields' => 'ids' ) );
echo reset( $term_list ); ?> program-<?php $term_list = wp_get_post_terms( $post->ID, 'program', array( 'fields' => 'ids' ) );
echo reset( $term_list ); ?> language-<?php $term_list = wp_get_post_terms( $post->ID, 'language', array( 'fields' => 'ids' ) );
echo reset( $term_list ); ?>">
  <div class="card-item_top">
    // Какой-то код....
  </div>
  <div class="card-item_middle">
    // Какой-то код....
  </div>
  <div class="card-item_bottom">
    // Какой-то код....
  </div>
</div>
<?php  endwhile;   ?>
<?php wp_reset_postdata(); ?>
// Пагинация
<nav class="pagination">
  <?php
    $big = 999999999;
    echo paginate_links( array(
      'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
      'format' => '?paged=%#%',
      'current' => max( 1, get_query_var('paged') ),
      'total' => $loop->max_num_pages,
      'prev_text' => '&laquo;',
      'next_text' => '&raquo;'
    ) );
  ?>
</nav>
</code>
</spoiler>

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