Programatically hide expired post

Hi to all wix programmers!

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!

Best Regards,

Kenneth Lim

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?

Thanks,
Tal.

Hello Tal,

Sorry for the late reply! Yepp I’ve created my own website and I’m uploading the posts via database dynamically!

Best Regards,

Kenneth Lim

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 hope it’s clear.

Good luck,
Tal.

Thanks for the help Tal,

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. 
        
    }); 

});

Best Regards,

Kenneth Lim

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.

Have a good day,
Tal.

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?

Thanks in advance for any tips!

Please have a read of our Forum Guidelines and put your post as a new post rather than jumping onto a post that is two years old now.

As for working with the Wix Blog app, you can use it with code however note that you are limited in certain ways.

See here for working with the Wix Blog app collections, so that you can see what you can do with each field from the collections and by how you can query/filter them etc.
https://support.wix.com/en/corvid-by-wix/wix-blog-with-corvid

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

Finally, you can have a read of PostPage from Wix API Reference here.
https://www.wix.com/corvid/reference/$w.PostPage.html

This forum post will now be closed, if you need anymore help with this then please post a new forum post.

Plus, as you mention Events, do you actually mean about using Wix Events app?

As if you do then again see the collections info for it.
https://support.wix.com/en/corvid-by-wix/wix-events-with-corvid

You can also create your own custom events page as shown here.
https://support.wix.com/en/article/creating-a-custom-events-gallery
https://support.wix.com/en/article/creating-a-custom-event-details-page