UPDATE!!!
It’s taken me a week, but I figured out how to do everything I was asking in my post. I’m sharing that code solution here for anyone else who has a similar question or use.
You can use this code and setup for a LOT of different applications on various websites. (I added explanations within the code with the double backslash to comment it out so it is easier to find stuff in your developer console in Wix.) Here is the code I wrote, which works.:
(sorry for the layout, I don’t know how to fix that in this forum)
//______________________________________________
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
let filteredResults = ; // Define a variable to store the filtered results globally
$w.onReady(function () {
//
__________________________________THIS CHANGES THE TEXT TO SET UP FOR FILTERING OTHER REPEATERS.
const Repeater1 = $w(“#Repeater1”); // This is the first repeater. In my case, it’s for book genres.
const TextElement1 = $w(“#TextElement1”); // This is a text element that’s separate from the repeaters. When you click on a genre card, it changes the value of this text, and that value also gets used later in the code to filter the second card repeater (in my case, that repeater is the series repeaterj).
Repeater1.onItemReady(($item, itemData, index) => {
const repeater1Pic = $item("#repeater1Pic"); // Get Repeater1's pic and a corresponding text element on the repeater card.
const repeater1Text = $item("#repeater1Text");
repeater1Pic.onClick(() => {
TextElement1.text = repeater1Text.text;
let sFilter = $w('#TextElement1').text; // This sets the text value of the name of the card you click on in Repeater1.
console.log(sFilter);
});
});
});
//
filter the repeater with the text element________________________________________________________________ (I HAVE STAGE 1 DONE: WRITE CODE TO POPULATE INTO CODE VIEWER. STAGE 2 WILL INCLUDE TYING THAT DATA TO A TEST-REPEATER THAT ISN’T LINKED TO DATABASE ANY WAY EXCEPT THROUGH THE CODE FO WHAT’S POPULATED INTO THE CODE VIEW.
)
//1.d) 

STAGE ONE USES THIS CODE. BUT THEN WE’LL HAVE TO CONNECT THE ARRAY THAT’S WRITTEN IN CODE VIEW TO A TEST REPEATER IN STAGE 2. 

$w(“#repeater1Pic”).onClick(() => {
const REPEATER1TEXT = $w(“#TextElement1”).text; // Get the text value from your TextElement1 element
// Query the second database to find rows that match the Repeater1 Text element
wixData.query("collection_1_id") // ID of your second database collection
.eq("g", REPEATER1TEXT) // Change "g" to the first collection's primary field id. "REPEATER1TEXT" is the item id of the text element on the card in Repeater1, and it will display the name of the item.
.find()
.then((secondDatabaseResults) => {
// Extract the row IDs of matching rows
const matchingRowIds = secondDatabaseResults.items.map(item => item._id);
// Query the first database and filter based on the matching row IDs from the second database
wixData.query("collection_2_id") // Replaced "collection_2_id" with the actual id of your first database collection
.hasSome("C2_MultiRef_Field_ID", matchingRowIds) // "C2_MultiRef_Field_ID" is the id of the multiref field in the second collection, where selections are made from the first collection.
.find()
.then((firstDatabaseResults) => {
console.log("Filtered results from the first database:", firstDatabaseResults.items);
filteredResults = firstDatabaseResults.items; // Assign the filtered results to the global variable
// Create an object to store dynamic link URLs for each of the second repeater's items.
const dynamicLinks = {};
// Query the dynamic link URLs for each series
Promise.all(filteredResults.map(item => {
const REPEATER2TEXT = item.s; //"s" is the primary field id in the second collection
return wixData.query("collection_2_id")
.eq("s", REPEATER2TEXT) // Change "s" to the second collection's primary field id. "REPEATER2TEXT" is the item id of the text element on the card in Repeater2, and it will display the name of the item.
.find()
.then((result) => {
const firstResultItem = result.items[0];
if (firstResultItem) {
const dynamicLinkURL = firstResultItem["c2_multiref_id"]; //✏ Add the field id of the multiref field in the second collection. (That's the field that allows you to make multiple selections from the first collection.)
dynamicLinks[REPEATER2TEXT] = dynamicLinkURL;
}
});
})).then(() => {
// Populate the second repeater with the filtered results
$w("#Repeater2").data = filteredResults; // This is the second repeater, which is only connected, filtered, and populated by code.
// Bind the items to the elements in the repeater
$w("#Repeater2").forEachItem(($item, itemData, index) => {
$item("#Text2").text = itemData.s; // Bind the second repeater's collection's primary field id to the second repeater's text element
// Set the background image of the child element within the container
$item("#repeater2Image_ID").src = itemData.pic; // "repeater2Image_ID" is the picture that was added onto the container in Repeater2. "pic" is the field id in the second collection, where you want to pull images from.
// Attach the dynamic link URL to the second collection's image element's data attribute
const dynamicLinkURL = dynamicLinks[itemData.s]; //"s" is the primary field id in the second collection
if (dynamicLinkURL) {
$item("#repeater2Image_ID").link = dynamicLinkURL;
} else {
console.error("Dynamic link URL is missing for second database:", itemData.s); //"s" is the primary field id in the second collection
}
});
//Now setting up a click for the 2nd repeater's image - MAKE SURE YOU HAVE AN EXTRA IMAGE ON TOP OF THE REPEATER ITEM CONTAINER. THAT IS THE IMAGE THAT WILL BE LINKED TO THE COLLECTION, CUZ YOU CAN'T CHANGE THE BACKGROUND OF THE CONTAINER IN THE CODE.
$w("#Repeater2").onItemReady(($item, itemData, index) => {
$item("#repeater2Image_ID").onClick(() => {
// Handle navigation to the dynamic second collection's page
const dynamicLinkURL = dynamicLinks[itemData.s]; //"s" is the primary field id in the second collection
if (dynamicLinkURL) {
wixWindow.openLightbox(dynamicLinkURL);
} else {
console.error("Dynamic link URL is missing for second collection:", itemData.s); //"s" is the primary field id in the second collection
}
});
});
}).catch((error) => {
// Handle errors
console.error("Error querying data:", error);
});
});
});
});