• I am working with a plugin that I kinda pieced together from others which works very well. It is a recent posts plugin that displays certain info for the most recent posts. All that works; however, I cannot only pull based on category, which is vital to my application. Essentially, right now, the SQL query pulls all recent posts and I want to modify the SQL query to pull only recent posts in ONE category only. However, I am confused as to how to do this.

    Here is the query I have currently, could someone take a look at it and possibly give me some direction? Thanks.

    $request = $wpdb->prepare("SELECT ID, post_title, post_date, post_excerpt,LEFT(post_content,$sqllimit) AS short_post_content FROM $wpdb->posts WHERE post_status = 'publish' ");
    		if($hide_pass_post) $request .= "AND post_password ='' ";
    		if($include_pages) $request .= "AND (post_type='post' OR post_type='page') ";
    		else $request .= "AND post_type='post' ";
    		$request .= "AND post_date_gmt < '$now' ORDER BY post_date DESC LIMIT $skip_posts, $returnnum";

    Mike

Viewing 1 replies (of 1 total)
  • Using the Echo Query plugin this code in the WordPress Default theme just before the loop:
    query_posts('cat=77');

    cause this SQL to be used:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_term_taxonomy.taxonomy = ‘category’ AND wp_term_taxonomy.term_id IN (’77’) AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5

Viewing 1 replies (of 1 total)
  • The topic ‘SQL Call to pull posts ONLY in certain categories’ is closed to new replies.