---
agentTools:
  projectIndex: https://olympus.readme.io/llms.txt
---

# Use Search Engine

The Tea Theme Options is provided with a list of plugins, such as a super powerfull Search Engine which uses ElasticSearch.
Here is how to display results from the Search Engine.

[block:code]
{
  "codes": [
    {
      "code": "<?php\n  //Get results from Tea_Theme_Options, instance of `$tea` variable.\n  $results = $tea->search()->searchContents();\n?>\n<?php if ($results['total']): ?>\n  <aside class=\"filter-search\">\n    <ul>\n      <?php foreach ($results['types'] as $typ): ?>\n        <li><?php echo $typ ?> (<?php echo count($results['results'][$typ]) ?>)</li>\n      <?php endforeach ?>\n    </ul>\n  </aside>\n\n  <section class=\"results\">\n    <?php foreach ($results['results'] as $type => $type_res): ?>\n      <h2><?php echo sprintf(__('%s (%d)'), $type, count($type_res)) ?></h2>\n      <div class=\"row\">\n        <?php foreach ($type_res as $res): ?>\n          <?php\n            //Get source and score.\n            $score = $res['score'];\n            $source = $res['source'];\n            //Get datas.\n            $id = $source['id'];\n            $title = $source['title'];\n            $content = $source['content'];\n            //Include template.\n            if ('category' == $type || 'post_tag' == $type) {\n              $link = get_term_link(intval($id), $type);\n          ?>\n\n<article class=\"article\" itemscope itemtype=\"http://schema.org/BlogPosting\">\n  <h3 itemprop=\"name\"><?php echo $title ?> (<?php echo $score ?>)</h3>\n  <?php if (!empty($content)): ?>\n    <div class=\"media-content\" itemprop=\"headline\"><?php echo $content ?></div>\n  <?php endif ?>\n  <a href=\"<?php echo $link ?>\" title=\"<?php echo esc_html($title) ?>\" itemprop=\"url\"><?php _e('See all') ?></a>\n</article>\n\n        <?php\n            }\n            else if ('post' == $type) {\n              $date = isset($source['date']) ? date('j F Y à H:i', strtotime($source['date'])) : date('j F Y à H:i');\n              $excerpt = isset($source['excerpt']) ? $source['excerpt'] : '';\n              $link = get_permalink($id);\n              //get author datas\n              $author = array(\n                'id' => $source['author'],\n                'name' => get_the_author_meta('display_name', $source['author']),\n                'link' => get_author_posts_url($source['author'])\n              );\n              //get date datas\n              $date = array(\n                'complete' => date('c', strtotime($source['date'])),\n                'display' => date('j F Y à H:i', strtotime($source['date']))\n              );\n          ?>\n\n<article class=\"article\" itemscope itemtype=\"http://schema.org/BlogPosting\">\n  <aside class=\"post-categories\" itemprop=\"keywords\">\n    <ul>\n      <?php get_the_term_list($id, 'category', '<li>', ',</li><li>', '</li>') ?>\n    </ul>\n  </aside>\n\n  <?php if (has_post_thumbnail($id)):\n    $image = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');\n  ?>\n    <a href=\"<?php echo $link ?>\" title=\"<?php echo esc_html($title) ?>\" class=\"thumbnail\" itemprop=\"url\">\n      <img src=\"<?php echo $image[0] ?>\" alt=\"\" width=\"<?php echo $image[1] ?>\" height=\"<?php echo $image[2] ?>\" />\n    </a>\n  <?php endif ?>\n\n  <h3 itemprop=\"name\"><?php echo $title ?> (<?php echo $score ?>)</h3>\n  <span class=\"media-time\">\n    <?php echo sprintf(\n      __('By <a href=\"%s\" itemprop=\"author\">%s</a> on <time datetime=\"%s\" itemprop=\"datePublished\">%s</time>'),\n      $author['link'],\n      $author['name'],\n      $date['complete'],\n      $date['display']\n    ); ?>\n  </span>\n\n  <div class=\"media-content\" itemprop=\"headline\"><?php echo $excerpt ?></div>\n  <a href=\"<?php echo $link ?>\" title=\"<?php echo esc_html($title) ?>\" itemprop=\"url\"><?php _e('Read more') ?></a>\n</article>\n\n        <?php\n            }\n          ?>\n        <?php endforeach ?>\n      </div>\n    <?php endforeach ?>\n  </section>\n<?php else: ?>\n  <section class=\"results\">\n    <div class=\"row\">\n      <p><?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.') ?></p>\n    </div>\n  </section>\n<?php endif ?>\n",
      "language": "php"
    }
  ]
}
[/block]