Modify Wordpress SQL Query to pull from within a category

Posted by Levi on Stack Overflow See other posts from Stack Overflow or by Levi
Published on 2011-01-07T15:31:53Z Indexed on 2011/01/07 15:54 UTC
Read the original article Hit count: 578

Filed under:
|
|
|
|

Hi

I am using a wordpress plugin called "kf most read" which stores a count of how many times a post was read, and lets you output a list of most read posts.

This works well. The issue is, I am trying to pull the most read posts, but only the most read posts within the current category you are viewing.

I am close to clueless when it comes to sql.

Here us what the plugin is currently using to pull the most read posts:

$sql = "SELECT count(mr.post_ID) as totHits, p.ID, p.post_title from $wpdb->posts p JOIN {$wpdb->prefix}kf_most_read mr on mr.post_ID = p.ID where mr.hit_ts >= '".(time() - ( 86400 * $period))."' GROUP BY mr.post_ID order by totHits desc, ID ASC LIMIT $limit";

How could I incorporate the below query which pulls from a specific category into the above?

$sql .= "LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)" ; $sql .= "WHERE $wpdb->term_taxonomy.term_id IN ($currentcat)" ; $sql .= "AND $wpdb->term_taxonomy.taxonomy = 'category'" ;

Any Help on this would be much appreciated.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql