Answer the question
In order to leave comments, you need to log in
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(); ?>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question