• Resolved theredeclipse

    (@theredeclipse)


    Hello everyone. I have a code which displays a posts with thumbnails on my front page. Now I want to make this work on a separate category. I’ve added array( 'cat' => '22' ) into WP_Query as codex says, but it doesn’t work – loads posts no matter what category is content from.

            <?php $the_query = new WP_Query( 'posts_per_page=3', array( 'cat' => '22' ) ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
                  <div class="col-lg-4 col-md-6 mb-sm-50">
                    <div class="blog-post wow fadeIn" data-wow-duration="2s" style="visibility: visible; animation-duration: 2s; animation-name: fadeIn;">
                    <!-- Image --><a class="post-img" href="<?php the_permalink() ?>"><?php
                    if ( has_post_thumbnail() ) {  the_post_thumbnail('full');  } ?></a><div class="bp-content"><p><!-- Meta data --></p><div class="post-meta"><a class="post-date" href="<?php the_permalink() ?>"> <i class="fa fa-calendar-o"></i><?php echo get_the_date(); ?></a></div><h4><?php the_title(); ?></h4><!-- Blurb --><!-- Link --><?php $mycontent = get_the_content();
      $trimmed_content = wp_trim_words( $mycontent , 15, '<a href="'. get_permalink() .'">...</a>' ); ?>
      <p><?php echo $trimmed_content; ?></p> <a class="btn btn-small" href="<?php the_permalink() ?>">Read More</a></div>
                    </div>
                  </div>
                <?php
            endwhile;
            wp_reset_postdata();
            ?>

    Can you help me please?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query Show posts for category’ is closed to new replies.