Display posts by category

Question

I have this code that is displaying a list of my blogposts on my index.
What I would like is to add a category parameter to it, to only display a list of the posts with a specific category.
I don’t seem to be able to do it, without breaking everything…

Thanks for your precious help.

    <?php $all_posts = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1 ) );

if ( $all_posts->have_posts() ):?>

    <ul>
        <?php while ( $all_posts->have_posts() ) : $all_posts->the_post();  global $post;
            ?>

            <li class='sub-menu'> 
                <a href='#' class="exposition"  data-id="<?php the_id();?>"><?php the_title(); ?></a>
                <ul>
                    <li>
                        <?php the_content(); ?>
                    </li>
                </ul>
            </li>
            <?php $images = get_field('gallery');?>

        <?php endwhile; ?>
        <?php else : ?>

        <?php endif; ?>
0
, pual 1 year 2020-07-22T09:10:29-05:00 0 Answers 49 views 0

Leave an answer

Browse
Browse