term_taxonomy.' tt, ' . $wpdb->term_relationships.' tr WHERE tt.taxonomy = \'category\' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = '.$post->ID; $cats = $wpdb->get_results($q); foreach(($cats) as $cat) { if (in_array($cat->term_id, $exclude) != false){ return; } } } if(!$post->ID){return;} $now = current_time('mysql', 1); $tags = wp_get_post_tags($post->ID); $taglist = "'" . $tags[0]->term_id. "'"; $tagcount = count($tags); if ($tagcount > 1) { for ($i = 1; $i < $tagcount; $i++) { $taglist = $taglist . ", '" . $tags[$i]->term_id . "'"; } } $limit = $wp_rp["wp_rp_limit"]; if ($limit) { $limitclause = "LIMIT $limit"; } else { $limitclause = "LIMIT 5"; } $q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;"; $related_posts = $wpdb->get_results($q); $output = ""; if (!$related_posts){ $wp_no_rp = $wp_rp["wp_no_rp"]; $wp_no_rp_text = $wp_rp["wp_no_rp_text"]; if(!$wp_no_rp || ($wp_no_rp == "popularity" && !function_exists('akpc_most_popular'))) $wp_no_rp = "text"; if($wp_no_rp == "text"){ if(!$wp_no_rp_text) $wp_no_rp_text= ""; $output .= '