Currently I have individual post which have a date attached to it dynamically. Hence, if the date has passed, I would love to hide the post from my website, any chance someone did this before? Thank you!
Hi Kenneth,
To which post you were referring? Have you created your own post using code and editor elements? Or do you refer to Wix Blog / Wix Forum posts?
Hi,
If you’ve connected your DB collection to a repeater and you would like to filter all posts with a date that has passed, you would need some coding:
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query("collectionName")
//find all future dates
.gt("date", new Date())
.find()
.then((results) => {
//setting all the filtered data to the repeater
$w(`#repeater1`).data = results.items;
})
.catch((err) => {
let errorMsg = err;
});
$w(`#repeater1`).onItemReady(($w, itemData) => {
//setting here all the elements information
//in this case, the button's label.
$w(`#button1`).label = itemData.title;
});
});
If you want to display the posts of the current day as well, you would need to change the date object. Click here to learn more about the Date object functions. Click here to learn more about the gt( ) function.
I’ve been trying out for a few days but I’m not too good at programming. I roughly understand the gt() function but how do I implement it if I would want to check my column name “Expiry” which is in date/time format, to the current date/time now>
I’ve looked through the Date object functions, I’ve tried using Date.now() but it didn’t work as I would like to. In addition, for your information, my objective is to not show those post that are “expired”. Appreciate your help once again Tal!
This is my current code:
$w.onReady(function () {
wixData.query(“Deals”)
//find all future dates
.gt(“Expiry”, new Date())
.find()
.then((results) => {
//setting all the filtered data to the repeater
let
$w(`#gallery1`).data = results.items;
})
.catch((err) => {
let errorMsg = err;
});
$w(`#gallery1`).onItemReady(($w, itemData) => {
//setting here all the elements information
//in this case, the button's label.
});
Hi Kenneth,
Firstly, you need to make sure that the IDs are set properly .
Secondly, the field key starts with lower case, so it should be changed to:
.gt(" e xpiry", new Date()).
Moreover, you haven’t set the data to repeater items- the onItemReady function is without any elements. I recommend reading the API documentation to be familiar with the code syntax.
Greetings. I’m new to Wix and Corvid but have programming experience (including JS, TS, node). I have a similar need but I’m using the built-in Wix Blog App.
In short, I’m using this App to show current and upcoming events through the year. Users can only view (no commenting, no posting, etc.). Each event is a separate post with a unique date range. I need to be able to assign a date range to each post so that it is only visible during that window. (I chose not to use a Repeater because of its restriction that all entries be formatted the same way)
Any suggestions? Should I create a database with <key, start_date, stop_date> where key matches some unique identifier (such as the hidden ID field) in the Blog database and use code to manage the visibility?
Plus, there are a variety of Wix Corvid examples/tutorials for working with the Wix Blog as shown in the Wix Corvid Examples page here. https://www.wix.com/corvid/examples