Goal: Hide some dynamic item pages
Background: I want to filter out those pages with code. No-code dataset filters can’t be used as this filter requires coded functions.
Question: I’ve achieved this filter on the dynamic list page. Just need it replicated on its dynamic item pages
Working page code on dynamic list page:
import wixData from 'wix-data';
$w.onReady(async function () {
let filter = wixData.filter();
filter = filter.ne("hide", true); //to filter out items whose 'hide' field is true
//To filter out based on another function
const memberIds = await getInactiveOrders();
filter = filter.not(
filter.hasSome('_owner', memberIds)
.and(filter.eq('status', ["Premium"]))
)
$w('#listingsDataset').setFilter(filter);
});
Failed attempts as a noob
// Approach 1) Just replacing the dataset name in the above code
// Approach 2) Adding the following bit, then setting the filter on the item
$w.onReady(async function () {
const dataset = $w('#dynamicDataset');
dataset.onReady(async () => {
let currentItem = dataset.getCurrentItem();
//filter...
// Approach 3) AI
$w.onReady(async function () {
const dataset = $w('#dynamicDataset');
dataset.onReady(async () => {
let currentItem = dataset.getCurrentItem();
if (currentItem.hide === true) {
blockItem();
return;
}
const memberIds = await getInactiveOrders();
if (memberIds.includes(currentItem._owner) && currentItem.status === "Premium") {
blockItem();
}
});
});
import wixLocation from 'wix-location';
function blockItem() {
wixLocation.to("/not-available"); // Redirect to a page
}
Working in Wix Editor