# Blog search

**URL:** <https://community.hubspot.com/t/blog-search/57955>\
**Category:** CMS Development\
**Created:** [May 30, 2022, 7:30am UTC](https://community.hubspot.com/t/blog-search/57955 "2022-05-30T07:30:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielPerte](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gabrielperte/32/77566_2.png) [@GabrielPerte](https://community.hubspot.com/u/GabrielPerte)\
**Post date:** [May 30, 2022, 7:30am UTC](https://community.hubspot.com/t/blog-search/57955/1 "2022-05-30T07:30:32Z")

</div>

Hello, I’m trying to figure out how this blog search might be put together:

> **[Exposure Validation Thought Leadership | SafeBreach Blog](https://www.safebreach.com/blog/)**
>
> Learn about our latest cybersecurity threat research and coverage, product enhancements, insights, tips, and more.

Basically, after typing your search query, the blog index page should display the articles including the search query.

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [May 30, 2022, 12:48pm UTC](https://community.hubspot.com/t/blog-search/57955/2 "2022-05-30T12:48:28Z")

</div>

Hi @GabrielPerte,

this can be done via AJAX. So basically you’ll need to clone and modify the search module. I think @piersg has done something like that in the past

best,

Anton

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [May 31, 2022, 9:33am UTC](https://community.hubspot.com/t/blog-search/57955/3 "2022-05-31T09:33:50Z")

</div>

Gabriel messaged me directly but to help others, I think searching on keyup would work e.g.

```lia-code-sample
const input = document.getElementById('blog-search-input');
input.onkeyup = (e) => {
 let input_val = this.value;
 const listSelector = documents.getElementsByClassName('blog-listing-wrapper')[0]; // whatever div wraps your blog listings

 if (input_val.length > 0) {
 let request = new XMLHttpRequest();
 request.open('GET', "https://api.hubapi.com/contentsearch/v2/search?portalId=[PORTAL ID]&term="+input_val+"&type=BLOG_POST&length=SHORT", true);

 request.onload = function() {
 if (this.status >= 200 && this.status < 400) {
 // Success!
 let data = JSON.parse(this.response);
 let results = data.results;
 let amount = results.length;
 if (results === undefined || results.length == 0) { 
 listSelector.innerHTML = "";
 listSelector.innerHTML += "<p style='margin: 0 auto;'>Sorry, there are no results for that search. Please search something else.</p>"
 } else {
 results = Array.from(results);
 results.forEach(node => {
 let date = node.publishedDate;
 let tag = node.tags[0];
 // structure this html for each result however you structure your blog listings normally
 listSelector.innerHTML += "<div class='post-item content-item'><div class='img-wrapper mb-20 blog-featured-image-wrapper blog-search-image'><a href="+ node.url + " class='hs-featured-image-link'><img src="+ node.featuredImageUrl + "></a></div><p id='hubspot-topic_data'>" + tag + "</a> |  " + date + "</p><div class='post-header blog-title'><h3 class='h5'><a href="+ node.url + " >"+ node.title + "</a></h3></div><div class=' blog-body clearfix'><p>"+ node.description + "</p></div></div></div>"
 });
 } 
 } else {
 // We reached our target server, but it returned an error
 console.log(this.response);
 listSelector.innerHTML = "";
 listSelector.innerHTML += "<p style='margin: 0 auto;'>Sorry, there was an error</p>"
 }
 };

 request.onerror = function(status, error) {
 console.log(error);
 };

 request.send();
 }
}

```
