/** * Get last answer or comment. * * @param bool $onlyVisible default true * @return CMA_Answer|CMA_Comment */ public function getLastComment($onlyVisible = true) { global $wpdb; // if( empty($format) ) // { // $format = get_option('date_format') . ' ' . get_option('time_format'); // } $records = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments}\n \tWHERE comment_post_ID = %d AND comment_approved = 1\n \tORDER BY comment_ID DESC", $this->getId())); foreach ($records as $record) { if ($record->comment_type == CMA_Answer::COMMENT_TYPE) { if ($answer = new CMA_Answer($record)) { if (!$onlyVisible or $answer->isVisible()) { return $answer; } } } else { if ($comment = new CMA_Comment($record)) { if (!$onlyVisible or $comment->isVisible()) { return $comment; } } } } // $lastAnswer = $this->getLastAnswer(); // if( $lastAnswer ) // { // $dateString = $lastAnswer->getDate(); // } // else // { // $dateString = $this->post->post_modified; // } // return date_i18n($format, strtotime($dateString)); }