Title: Display Posts By Category
Last modified: August 20, 2016

---

# Display Posts By Category

 *  [herold](https://wordpress.org/support/users/herold/)
 * (@herold)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/display-posts-by-category/)
 * I have the following custom query and I would like to add the functionality to
   also search by category. Can someone help me with the code to add?
 * SELECT $wpdb->posts.* FROM $wpdb->posts
    WHERE $wpdb->posts.post_status = ‘publish’
   AND $wpdb->posts.post_type = ‘page’ AND $wpdb->posts.post_date > ‘”.$wbc_new_date_start.”‘
   AND $wpdb->posts.post_date < ‘”.$wbc_new_date_end.”‘ ORDER BY $wpdb->posts.post_date
   ASC “;

Viewing 1 replies (of 1 total)

 *  Thread Starter [herold](https://wordpress.org/support/users/herold/)
 * (@herold)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/display-posts-by-category/#post-2338752)
 * Here is the solution:
 * $wbc_query = “
    SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships
   ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy
   ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
   WHERE $wpdb->posts.post_status = ‘publish’ AND $wpdb->term_taxonomy.term_id =‘”.
   $category_name.”‘ AND $wpdb->term_taxonomy.taxonomy = ‘category’ AND $wpdb->posts.
   post_type = ‘post’ AND $wpdb->posts.post_date > ‘”.$wbc_new_date_start.”‘ ORDER
   BY $wpdb->posts.post_date ASC “;

Viewing 1 replies (of 1 total)

The topic ‘Display Posts By Category’ is closed to new replies.

## Tags

 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [herold](https://wordpress.org/support/users/herold/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/display-posts-by-category/#post-2338752)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
