H
H
HamSter2019-02-26 13:36:34
WordPress
HamSter, 2019-02-26 13:36:34

How to display posts from a specific category or with a specific tag?

I create posts with the same work.
category. I try to display posts from a specific category:

<?php
  global $post;

  $postslist = get_posts( 
    array( 
      'posts_per_page' => -1,         
      'category'       => 'work',     
      'order'          => 'ASC'
     ) 
  );

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

  $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); 
 ?>
  <div class="col-6 col-sm-3 element-item">
    <div class="portfolio-item">
    <?php 
      echo '<a href="'.esc_url($featured_img_url).'" data-fancybox="portfolio">'; 
         the_post_thumbnail();
      echo '</a>';
    ?>
  </div>
 </div>
                        
<?php
}
wp_reset_postdata();  ?>

But the page displays all posts with different headings.
Question: How to display posts from a specific category or with a specific tag?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2019-02-26
@HamSter007

And so?

$postslist = get_posts( 
    array( 
      'posts_per_page' => -1,         
      'category_name'       => 'work',     
      'order'          => 'ASC'
     ) 
  );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question