Title: hard coding an sql query
Last modified: August 18, 2016

---

# hard coding an sql query

 *  Resolved [public_radio](https://wordpress.org/support/users/public_radio/)
 * (@public_radio)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/hard-coding-an-sql-query/)
 * Hi,
 * I really need this anwered. It’s in relation to this issue:
 * [http://wordpress.org/support/topic/91869](http://wordpress.org/support/topic/91869)
 * So anyway, I need to send a hard-coded sql query to find all posts in a certain
   category, and I need to know what the standard query is that wordpress uses for
   this so that I can take out the_loop and WP_Query and just use the sql query.
   What is the query? thanks.

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

 *  Thread Starter [public_radio](https://wordpress.org/support/users/public_radio/)
 * (@public_radio)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/hard-coding-an-sql-query/#post-476515)
 * Come on. this HAS to be a question that a number of you know the answer to. What
   is the deal?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/hard-coding-an-sql-query/#post-476593)
 * First thing to learn is that a little patience can go a long way…
 * A query line that collects posts from a specific category using WordPress’ database(
   $wpdb) class would look something like this:
 * `$my_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->
   post2cat ON ID = post_id WHERE category_id = 3 AND post_status = 'publish' ORDER
   BY post_date DESC LIMIT 0, 10");`
 * If using standard PHP functions to work the SQL query, just replace `$wpdb->`
   in the query clauses with your table prefix (i.e. `wp_`).

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

The topic ‘hard coding an sql query’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * Last activity: [19 years, 6 months ago](https://wordpress.org/support/topic/hard-coding-an-sql-query/#post-476593)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
