D
D
Denis2021-09-19 13:41:20
PHP
Denis, 2021-09-19 13:41:20

Wordpress button click show categories of this post in a modal window?

Can you help.
There is a button for each post, when clicked, a modal window appears in which I want to display all the categories of this post on which the button was pressed. How to do it? Post ID data I got Ajax

<?php

  define('WP_USE_THEMES', true);

  include('../../../wp-load.php');
  $id = $_POST['id'];
  $post = get_post($id);


How do I now get the category ID and pass it to get_post ? Now I'm displaying post categories like this:

<div class="swiper-wrapper">
    <?php
                                    // параметры по умолчанию
    $posts = get_posts( array(
        'numberposts' => 1000,
        'category'    => 2,
        'orderby'     => 'date',
        'order'       => 'DESC',
        'post_type'   => 'post',
        'suppress_filters' => true,
    ) );

    foreach( $posts as $post ){
        setup_postdata($post);
        ?>
        <div class="swiper-slide">
            <article class="article-card">
                <div class="article-thumb">
                    <?php if ( has_post_thumbnail()) { ?>
                       <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                        <?php the_post_thumbnail(array(320, 250)); ?>
                    </a>
                <?php } ?>
            </div>
            <div class="article-card__content">
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <?php the_excerpt(); ?>
            </div>
            <div class="article-footer">
                <div class="date"><?php echo get_the_date(); ?></div>
                <a href="<?php the_permalink(); ?>" class="more-link">Подробнее</a>
            </div>
        </article>
    </div>
    <?php
}

wp_reset_postdata();
?>
</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