If you’d like to be able to search both your Media Library files and pages/posts, the following Javascript can get the job done. Just ensure that you place the code on your search results page, along with the shortcode to embed FileBird.
document.addEventListener("DOMContentLoaded", function () {
// Function to trigger input change event on a given node
const triggerInputChange = (node, value = "") => {
// Get the setter function for the 'value' property of the node
const setValue = Object.getOwnPropertyDescriptor(node.__proto__, "value").set;
// Create a new input event that bubbles up through the DOM
const event = new Event("input", { bubbles: true });
// Set the value of the node using the setter function
setValue.call(node, value);
// Dispatch the input event on the node
node.dispatchEvent(event);
};
// Execute code after a short delay to ensure that the DOM is fully loaded
setTimeout(() => {
// Find the search input element within an element with class 'fbdl-input-search'
const searchBox = document.querySelector(".fbdl-input-search input");
// Fetch the value of the 's' parameter from the query string in the URL
const urlParams = new URLSearchParams(window.location.search);
const searchTerm = urlParams.get("s");
// If the search input element exists and there is a search term in the URL
if (searchBox && searchTerm) {
// Set the fetched search term as the value for the search input
triggerInputChange(searchBox, searchTerm);
}
}, 100);
});