• Resolved public_radio

    (@public_radio)


    Hi,

    I really need this anwered. It’s in relation to this issue:

    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

    (@public_radio)

    Come on. this HAS to be a question that a number of you know the answer to. What is the deal?

    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.