Title: Pull post from a specific WordPress category
Last modified: August 19, 2016

---

# Pull post from a specific WordPress category

 *  [mccrum](https://wordpress.org/support/users/mccrum/)
 * (@mccrum)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pull-post-from-a-specific-wordpress-category/)
 * Hi, im looking to pull 3 posts from a specific WordPress Category. At the minute
   I can pull 3 latest posts and display them in a flash banner using the code below.
 *     ```
       SELECT yah_posts.*, yah_postmeta.*
       FROM yah_posts
       LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id
       WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish'
       ORDER BY post_date DESC LIMIT 3
       ```
   
 * I want to be able to pull 3 latest posts from a specific category instead of 
   just 3 latest posts from every category.
 * I have put together this code below, but it doesn’t seem to be working 🙁
 *     ```
       $query = "SELECT yah_posts.*, yah_postmeta.*
       FROM yah_posts
       LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id
       AND LEFT JOIN $yah_term_taxonomy ON($yah_term_relationships.term_taxonomy_id = $yah_term_taxonomy.term_taxonomy_id)
       WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish'
       AND $yah_term_taxonomy.term_id = '1'
       AND $yah_term_taxonomy.taxonomy = 'category'
       ORDER BY post_date DESC LIMIT 3";
       ```
   

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

 *  [g3legacy](https://wordpress.org/support/users/g3legacy/)
 * (@g3legacy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pull-post-from-a-specific-wordpress-category/#post-1890357)
 * Hi, will something like this work for you?
 *     ```
       $args = array( 'category_name' => 'your_category', 'numberposts' => '3', 'order'=> 'ASC' );
       $postslist = get_posts( $args );
       foreach ($postslist as $post) :  setup_postdata($post); ?> 
   
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
       <?php the_excerpt(); ?>
   
       <?php endforeach; ?>
       ```
   
 *  Thread Starter [mccrum](https://wordpress.org/support/users/mccrum/)
 * (@mccrum)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pull-post-from-a-specific-wordpress-category/#post-1890369)
 * Hi, im pulling data into an XML file which is then being displayed though a Flash
   Banner.
 * The first set of code above is working and pulling 3 latest posts but I need 
   3 latest posts from a specific category.
 *  [g3legacy](https://wordpress.org/support/users/g3legacy/)
 * (@g3legacy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pull-post-from-a-specific-wordpress-category/#post-1890373)
 * Unfortunately thats a bit beyond what I know about MYSQL queries.
 * Have you tried adding another WHERE or AND clause thats category specific?
 * Sorry, you may need to wait for someone a bit better than me to come along on
   this one ; )
 * Dan
 *  Thread Starter [mccrum](https://wordpress.org/support/users/mccrum/)
 * (@mccrum)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pull-post-from-a-specific-wordpress-category/#post-1890495)
 * Thanks for your help anyway 🙂

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

The topic ‘Pull post from a specific WordPress category’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [mccrum](https://wordpress.org/support/users/mccrum/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/pull-post-from-a-specific-wordpress-category/#post-1890495)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
