function mp_posts_in_cat($id_cat = array('all'),$the_limit = 7, $orderby = 'post_modified',$exclude = array('none')){ //declare global some wp database variables... global $wpdb, $tableposts, $tablepost2cat; //build WHERE clause for query (posts in category) if($id_cat[0] == 'all') { $where = ''; } else { $where = '('; foreach($id_cat as $cat) { $where .= "P2C.category_id = '$cat' OR "; } $where = substr($where, 0, strlen($where)-4); $where .= ') AND '; } //remove excluded posts from query results if(is_array($exclude) && $exclude[0] != 'none') { $where .= 'POST.ID != ('; foreach($exclude as $dontshow) { $where .='$dontshow, '; $where = substr($where, 0, strlen($where)-2); } $where .= ') AND '; } elseif(is_numeric($exclude)) { $where .= 'POST.ID != '.$exclude.' AND'; } //Limit clause if($the_limit != '' && is_numeric($the_limit)) { $the_limit = 'LIMIT '. $the_limit; } // the query $q = " SELECT P2C.*, POST.ID, POST.post_title, DATE_FORMAT('POST.post_date', '%m %d %y') AS post_date_formatted FROM $wpdb->posts POST, $wpdb->post2cat P2C WHERE $where POST.post_status = 'publish' AND POST.ID = P2C.post_id GROUP BY post_id ORDER BY POST.$orderby DESC $the_limit "; // do the query $arts = $wpdb->get_results($q); if ($arts){ //prepare output foreach ($arts as $art){ $output .= '
  • '.$art->post_date_formatted.''.$art->post_title.'
  • '; } } return $output; }