Hello, I know this is being asked a lot and there is some code out there but It doesn’t seem to work for me. It works on one page but doesn’t work on the results page with the same search bar. The search bar is in the header that is repeated throughout the site.
This is the code I have on the home page…
import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {
});
export function searchButton_click() {
let word = $w(“#searchBar”).value;
local.setItem(“searchWord”, word);
[wixLocation.to(/results
);](wixLocation.to(/results
);
})
[}](wixLocation.to(/results
);
})
This is what I have on the results page that has a search bar as well.
import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;
$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchBar”).value = sameWord;
$w(“#searchBar”).placeholder = sameWord;
$w(‘#dataset1’).onReady( function () {
search();
});
});
export function searchButton_click() {
search();
}
function search() {
wixData.query(‘AdvertisingServices’)
.contains(‘service’, $w(“#searchBar”).value)
.or(wixData.query(‘AdvertisingServices’).contains(‘title’, $w(“#searchBar”).value))
.find()
.then(res => {
$w(‘#allServices’).data = res.items;
});
}
Thank you so much for your help.