R
R
Roman Tuzov2020-07-07 00:52:00
WordPress
Roman Tuzov, 2020-07-07 00:52:00

The id from the taxonomy is not correctly set. How to fix?

I am making a filter for cards and each of the filters has its own taxonomy, which is called the same as the name of the filter.
Here is an example of two blocks ( They are all the same, they just have different names and did not insert everything ):

<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 value='language-{$cat->term_id}'>{$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 value='program-{$cat->term_id}'>{$cat->name}</option>";
              }
              echo '</select>';
      }
                  ?>
         </div>

Here you can see that I am displaying a list of programs and languages ​​from a taxonomy with a name and an individual id for it.
And here is the card block itself:
<?php  $query = new WP_Query( 'post_type=program-card' ); ?>
  <?php while ( $query->have_posts()):$query->the_post(); ?>
  <div class="card-item level-<?php the_field('card_level-id'); ?> direction-<?php the_field('card_direction-id'); ?> university-<?php the_field('card_university-id'); ?> program-<b><?php
  $categories = get_terms('program', 'orderby=name&hide_empty=0');
            if($categories){
                echo "{$cat->term_id}";
            }
            ?> language-<?php the_field('card_language-id'); ?></b>">
          // Здесь какой-то контент (Не важно, что внутри, важны классы выше)			
        </div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>

Now the filter works in such a way that it selects from its value the corresponding class in the card. Those. if program value="program-1096", then the card must have the same class: class="program-1096". The filter will detect and highlight the card you have selected from the list.
In GENERAL , now my id is set automatically for the entire list, as I wanted (blurred, but the code is visible on the right):
nDiOJCq9OkA.jpg
And for the cards, the id is set completely different and is the same for everyone. Well, according to my code, it’s clear why it’s the same) (I highlighted it in bold for convenience, as I now display id on cards).

Please help me make the same id for both the card and the appropriate name for it in the filter :)
I remind you that now programs display a completely different id, not like a card, and each one also has the same id.
PS Important! (Maybe :) ) I export cards via wp all import(pro). Because there are more than 500 of them and manually it takes a very long time. If you need to show how I output through import, then write in the comments.

Thank you very much in advance for at least thinking how to help me! ))

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