public function createResults( $offset ) {
$get_posts = new WP_Query;
$q = $this->search_string;
//Is Poterstemmer Active?
if ( read_option( 'sfs_is_stemmer' ) ) {
$stemmer = new PorterStemmer();
$q = $stemmer->Stem( $q );
}
$args = array(
'post_type' => read_option( 'sfs_search_in' ),
'post_status' => 'publish',
'post__not_in' => get_option('__protected_posts'),
'order' => read_option( 'sfs_search_order' ),
'offset' => $offset,
'order_by' => read_option( 'sfs_order_by' ),
'posts_per_page' => read_option( 'sfs_result_limit' ),
's' => $q
);
$posts = $get_posts->query( $args );
//$this->results = $posts;
if ( ! $get_posts->post_count ) {
wp_send_json_error( array( 'noresults' => true ) );
}
foreach ( $posts as $post ) {
//This Makes everything fucking slow
/* if ( $post->post_password == 'enter' ) {
return;
}*/
$this->results[] = array(
'id' => $post->ID,
'guid' => get_permalink( $post->ID ),
'title' => $post->post_title,
'thumbnail' => $this->add_thumbnail( $post->ID ),
'author' => $this->add_author( $post->post_author ),
'date' => date_i18n( get_option( 'date_format' ), strtotime( $post->post_date ) ),
//Generate the Content //Todo: needs some changes later
'content' => strip_tags( $post->post_content ),
//Generate the Comments
'comment_count' => $this->sfs_add_comments( $post->ID )
);
}
wp_reset_postdata();
wp_send_json_success( $this->results );
}