public function getPosts()
{
if ($this->disabled) {
return false;
}
$result = $this->search(['index' => $this->getIndexName(), 'type' => 'post', 'body' => $this->args]);
$this->found_posts = $result['hits']['total'];
if ($this->wp_query) {
$wpQuery = $this->wp_query;
$wpQuery->found_posts = $this->found_posts;
$ppp = $wpQuery->get('posts_per_page') ? $wpQuery->get('posts_per_page') : get_option('posts_per_page');
$wpQuery->max_num_pages = ceil($this->found_posts / $ppp);
}
$this->posts = [];
foreach ($result['hits']['hits'] as $p) {
$p = $p['_source'];
$this->posts[] = $post = new WP_Post(new stdClass());
$post->ID = $p['post_id'];
$post->site_id = get_current_blog_id();
$post->post_author = $p['post_author']['id'];
if (empty($p['site_id'])) {
$post->site_id = get_current_blog_id();
} else {
$post->site_id = $p['site_id'];
}
$post->post_type = $p['post_type'];
$post->post_name = $p['post_name'];
$post->post_status = $p['post_status'];
$post->post_title = $p['post_title'];
$post->post_parent = $p['post_parent'];
$post->post_content = $p['post_content'];
$post->post_excerpt = $p['post_excerpt'];
$post->post_date = $p['post_date'];
$post->post_date_gmt = $p['post_date_gmt'];
$post->post_modified = $p['post_modified'];
$post->post_modified_gmt = $p['post_modified_gmt'];
$post->permalink = $p['permalink'];
$post->post_mime_type = $p['post_mime_type'];
$post->menu_order = $p['menu_order'];
$post->guid = $p['guid'];
$post->comment_count = $p['comment_count'];
$post->filter = 'raw';
$post->elasticsearch = $p;
if ($this->updatePostTermCache) {
foreach ($p['terms'] as $taxonomy => $terms) {
foreach ($terms as $key => $value) {
$terms[$key] = $value = (object) $value;
$value->taxonomy = $taxonomy;
$value->filter = 'raw';
}
wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
}
}
if ($this->updatePostMetaCache) {
wp_cache_add($post->ID, $p['post_meta'], 'post_meta');
}
}
return $this->posts;
}