Title: Recent Posts Exclude Category
Last modified: August 20, 2016

---

# Recent Posts Exclude Category

 *  Resolved [pecado](https://wordpress.org/support/users/pecado/)
 * (@pecado)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/recent-posts-exclude-category/)
 * Hello,
 * I’m making own theme to my website. I’m in trouble with codes.
 * I want to recent 4 or 5 posts in all posts exclude one category.
 * My code is;
 * <?php
    $id = get_cat_id(‘portfolyo’); $q = “cat=-“.$id; query_posts($query_string.
   $q); ?>
 * <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
 * <?php endwhile; ?>
 * I put some code below, above my code, nothing is happen;
 * <?php
    $args = array( ‘numberposts’ => ‘2’ ); $recent_posts = wp_get_recent_posts(
   $args ); ?>
 * Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [pecado](https://wordpress.org/support/users/pecado/)
 * (@pecado)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/recent-posts-exclude-category/#post-3464848)
 * I’d tried $recent_posts codes couldn’t merge with my codes.
 * Any help please?
 *  Thread Starter [pecado](https://wordpress.org/support/users/pecado/)
 * (@pecado)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/recent-posts-exclude-category/#post-3464891)
 * I’d tried to page them except recent 4-5 posts showing.
 * I couldn’t have the right view.
 * Is there any help, please?
 *  Thread Starter [pecado](https://wordpress.org/support/users/pecado/)
 * (@pecado)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/recent-posts-exclude-category/#post-3464910)
 * At last, I solved the question. This is the answer.
 * <?php
 * $recentPosts = new WP_Query();
 * $id = get_cat_id(‘portfolyo’);
    $q = “cat=-“.$id;
 * $recentPosts->query(‘showposts=5&cat=’ .$q);
 * while ($recentPosts->have_posts()) : $recentPosts->the_post();
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Recent Posts Exclude Category’ is closed to new replies.

## Tags

 * [exclude category](https://wordpress.org/support/topic-tag/exclude-category/)
 * [theme development](https://wordpress.org/support/topic-tag/theme-development/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 3 replies
 * 1 participant
 * Last reply from: [pecado](https://wordpress.org/support/users/pecado/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/recent-posts-exclude-category/#post-3464910)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
