BuddyDev

Search

Auto expire wordpress post


  • Participant
    Level: Master
    Posts: 152
    Tosin on #25013

    Hello,

    How can I auto expire published post in a specific category. I have a category called sponsored but I want each article published in this category to auto expire (revert to draft or trash) after 30 days. A 30 day expiry time stamp will be applied immediately to every post published into the sponsored category. Please I don’t mean that all post in the sponsored category should expire at the same time, because the post are being published at different times, so the time stamp is applied per post.

    Thanks


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 879
    Ravi on #25014

    Hello Tosin,

    Thank you for posting. It can be doable using the WordPress Cron features. You can check the documentation here.

    https://codex.wordpress.org/Function_Reference/wp_schedule_event

    All you need to do is

    Step 1: Setup a cron job which runs daily one time.
    Step 2: With callback function get all the posts form your categories whose published date is older than 30 days.
    Step 3: Update post status

    Or check this plugin

    https://wordpress.org/plugins/post-expiration-date/

    Regards
    Ravi

    • This reply was modified 5 months, 3 weeks ago by  Ravi.

You must be logged in to reply to this topic.

This topic is: not resolved
Subscribe