Tutorial: Multi Page Searchbar.
This tutorial aims to show you how to create a searchbar that works on all your site pages.
//site code
import { local } from 'wix-storage';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w('#searchButton').onClick(function() {
let searchEntity = $w('#searchbar').value;
local.setItem("search", searchEntity);
wixLocation.to('/search-results');
});
});
//change '/search-results' to the url of your results page
//results page code
import { local } from 'wix-storage';
import wixData from 'wix-data';
$w.onReady(function () {
var checkQuery = local.getItem("search");
$w('#searchbar').value = checkQuery;
$w('#searchbar').placeholder = checkQuery;
$w('#searchResultsDataset').onReady(function () {
search();
});
$w('#searchButton').onClick(function () {
search();
});
function search() {
wixData.query('Database').contains('title', $w('#searchbar').value)
.or(wixData.query('Database').contains('description', $w('#searchbar').value))
.find()
.then(res => {
$w('#results').data = res.items;
});
}
});
/*change database to the name of your database.
Change title & description to fields you want to search */
//#results is a repeater