Title: WP Category Posts &#8211; Specify Amount
Last modified: August 18, 2016

---

# WP Category Posts – Specify Amount

 *  Resolved [krushinfo](https://wordpress.org/support/users/krushinfo/)
 * (@krushinfo)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/wp-category-posts-specify-amount/)
 * Hey,
 * I’m using a great plugin called ‘WP Category Posts’ which allows me to put a 
   categorys posts anywhere on my site. On specific pages or on the sidebar (with
   Exec-Php installed).
 * I’m just wondering if its possible to limit the amount to 10 entries.. I just
   want a sidebar with the last 10 news stories from a specific category.
 * Here is the code for the plugin..
 * `<?php
    /* Plugin Name: WP Category Posts Plugin URI: http://watershedstudio.
   com/portfolio/software/wp-category-posts.html Description: List the posts in 
   a specific category Author: Brian Groce Version: 1.0 Author URI: http://briangroce.
   com/ */  function wp_cat_posts( $catID ) {
 *  global $wpdb;
    $get_posts_in_cat = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title,";
   $get_posts_in_cat .= "$wpdb->post2cat.post_id, $wpdb->post2cat.category_id ";
   $get_posts_in_cat .= "FROM $wpdb->posts, $wpdb->post2cat "; $get_posts_in_cat.
   = "WHERE $wpdb->posts.ID = $wpdb->post2cat.post_ID "; $get_posts_in_cat .= "AND
   $wpdb->post2cat.category_id = '$catID' "; $get_posts_in_cat .= "AND $wpdb->posts.
   post_status = 'publish' "; $get_posts_in_cat .= "ORDER BY $wpdb->posts.post_title";
 *  $get_posts_in_cat_result = mysql_query($get_posts_in_cat);
    while ($posts_in_cat_row
   = mysql_fetch_assoc($get_posts_in_cat_result)) {  $post_title = $posts_in_cat_row['
   post_title']; $postID = $posts_in_cat_row['ID'];
 *  echo '<li><a href="' . get_permalink($postID) . '">' . $post_title . '</a><br/
   ></li>'; 
    }  } ?>
 * And you call the category like this
 * `<?php wp_cat_posts(2); ?>`
 * With the number corresponding to the category you want listed.
 * Any ideas?

Viewing 1 replies (of 1 total)

 *  [mtbello](https://wordpress.org/support/users/mtbello/)
 * (@mtbello)
 * [19 years ago](https://wordpress.org/support/topic/wp-category-posts-specify-amount/#post-485036)
 * I just figured this out. In the php file, use the following
 * …
    $get_posts_in_cat = “SELECT $wpdb->posts.ID, $wpdb->posts.post_title, “; $
   get_posts_in_cat .= “$wpdb->post2cat.post_id, $wpdb->post2cat.category_id “; 
   $get_posts_in_cat .= “FROM $wpdb->posts, $wpdb->post2cat “; $get_posts_in_cat.
   = “WHERE $wpdb->posts.ID = $wpdb->post2cat.post_ID “; $get_posts_in_cat .= “AND
   $wpdb->post2cat.category_id = ‘$catID’ “; $get_posts_in_cat .= “AND $wpdb->posts.
   post_status = ‘publish’ “; $get_posts_in_cat .= “ORDER BY $wpdb->posts.post_date
   DESC “; $get_posts_in_cat .= “LIMIT 10”; …

Viewing 1 replies (of 1 total)

The topic ‘WP Category Posts – Specify Amount’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [mtbello](https://wordpress.org/support/users/mtbello/)
 * Last activity: [19 years ago](https://wordpress.org/support/topic/wp-category-posts-specify-amount/#post-485036)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
