How can I only show items from a certain category (category 51)?
Here’s my loop below that I need to incorporate the code into.
<div class="news-content-inner">
<?php $portfolioloop = new WP_Query( array( 'paged' => get_query_var('paged'), 'post_type' => 'news', 'posts_per_page' => 4 ) ); ?>
<?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?>
<div class="news-item" onClick="location.href='<?php echo the_permalink(); ?>'">
<h2><a style="color:#F45B11!IMPORTANT;" href="<?php echo the_permalink(); ?>"><?php echo the_time('d.m.Y'); ?> / <?php echo the_title(); ?></a></h2>
<p class="news-page">
<?php if (get_field('description') != "") { ?>
<?php echo the_field('description'); ?>
<?php } else {
$newscontent = get_the_content();
$newscontent_str = strip_tags($newscontent, '');
echo substr($newscontent_str,0,250) . "â¦";
} ?>
</p>
</div>
<?php endwhile; // end of the loop. ?>
<p class="news-page" style="font-size:12px!IMPORTANT;"><?php echo wp_count_posts('news')->publish; ?> opportunities</p>
<?php if (function_exists('wp_pagenavi')) {
wp_pagenavi( array( 'query' => $portfolioloop ) ); } ?>
</div>
You need to modify your
WP_Query
loop. Add atax_query
argument to filter the category you want.http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters