I have a collection called “Lifestyle” it populates one page and every month the newest collection item replaces the previous content. Previously we were using the CMS visibility function so that we could pre-populate and schedule the newest post BUT that blocks us from having the ability to preview the content, WIX also doesn’t have a way to query hidden content for me to add to a “preview” page.
What I’ve tried so far
I removed the CMS visibility feature and added a “startDate” field to essentially look for the post that’s scheduled for that time. The problem is that it loads the newest posts first and then jarringly changes to the correct post which means users will see content that isn’t meant to be posted yet.
import wixData from 'wix-data';
$w.onReady(function () {
const d = new Date();
let today = new Date(d.setHours(0,0,0));
// Query for upcoming items
wixData.query("Lifestyle")
.eq("startDate", today)
.ascending("startDate")
.find()
.then((results) => {
if(results.items.length > 0) {
let item = results.items[0];
$w("#pageDataset").setFilter(
wixData.filter().eq("_id", item._id)
);
} else {
wixData.query("Lifestyle")
.lt("startDate", today)
.descending("startDate")
.find()
.then((results) => {
if(results.items.length > 0) {
let item = results.items[0];
$w("#pageDataset").setFilter(
wixData.filter().eq("_id", item._id)
);
} else {
console.log("No Results")
}
});
}
});
Extra context
I could remove the dataset connection from the page and attach every field manually but there’s A LOT of fields on this page which isn’t exactly convenient so I’m looking for a different option