0

Oh, hello! I want to show the three most recent blog posts in the home page, excluding the "featured" category, which has the ID 8. In order to see the ID for that category, I went to Posts > Category and hovered the cursor on it:

enter image description here

<div class="row">

<div class="col-xs-12 col-sm-8">
<?php
$args = array('posts_per_page' => 3, 'orderby' => DESC, 'cat=-8');
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
while(have_posts()):the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<?php endwhile;
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
</div>

<div class="col-xs-12 col-sm-4">
<?php get_sidebar(); ?>
</div>

</div>

I've experimented with several options and I can't find a solution. I hope you guys can help me. Cheers!

2

Your $args array is incorrect. You used cat=-8 which is not correct here. You will have to specify/exclude category this way 'cat' => -8. So your $args array will be

$args = array( 'posts_per_page' => 3, 'orderby' => DESC, 'cat' => -8 );
  • Gosh, thank you so much Robert. N00b error – user60184 Oct 28 '14 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy