R
R
ravlex2018-05-17 17:06:31
WordPress
ravlex, 2018-05-17 17:06:31

How to display WordPress posts with a list of their category IDs?

I have a taxonomy for which I display posts:

<?php
    global $post; 

    $args = array('numberposts' => -1, 'post_type' => 'catalog-object'); 

    foreach( $myposts as $post ){ setup_postdata($post); 

    $getcat = get_the_category(); ?>
<div class="category-<?php echo $cat->term_id; ?>"
 <!-- пытаюсь получить ID рубрики у каждой записи -->
      <?php the_title(); ?>
</div>
      <?php } wp_reset_postdata(); ?>

I need to display a record and a list of id next to it, in which this record is located.
So that the output is a div with the classes of each category (if not one). Example
<div class="category-1 category-2">
Запись 1
    </div>
    <div class="category-3 category-4">
Запись 2
    </div>

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