• Resolved defxs

    (@defxs)


    Hi,

    I am using WPallimport to import posts.
    I have a the following question.

    After WPallimport imports a post I call a function to get the post date and a certain date. I want to set that date as the expiry date for that post in publishpress.

    So my function will kind of look like this;

    function my_saved_post( $post_id ) {
       $date = get_the_time('Y-m-d', $post_id); // The publish date is set in the feature and post are already published. We use this date for events that happen in the feature
       $depublishtype = 'draft'; 
    
        Publish Press function to set the date( $post_id, $depublishtype );
    
        }
    
    add_action( 'pmxi_saved_post', 'my_saved_post', 10, 3 );

    So the variable $date that I am retrieving is an date in the feature. When we reach the day of the event it should be unpublished. That’s why I need a function to set it like this.

    Which of your functions do i need to call?

    • This topic was modified 2 years, 1 month ago by defxs.
    • This topic was modified 2 years, 1 month ago by defxs.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Riza Maulana Ardiyanto

    (@rizaardiyanto)

    The function postexpirator_schedule_event is the one that will schedule the expiration of the post, unpublishing it as draft on the specified date

    So it should be something like this

    <?php
    
    function my_saved_post($post_id)
    {
        $timestamp = get_the_time(
            'U',
            $post_id
        ); // The publish date is set in the feature and post are already published. We use this date for events that happen in the feature
    
        $opts = [
            'expireType' => 'draft',
            'enabled' => true,
        ];
    
        postexpirator_schedule_event($post_id, $timestamp, $opts);
    }
    
    add_action('pmxi_saved_post', 'my_saved_post', 10, 3);

    Note: We changed the date format to “U” on your code snippet

    Thread Starter defxs

    (@defxs)

    Hi,

    Perfect! That was what I was looking for.
    Thanks a lot.

    Kind regards,
    Mike

    Chad Holden

    (@holdench)

    Hi Riza I’m getting:
    PHP Deprecated: Function postexpirator_schedule_event is deprecated since version 2.8.0 with no alternative available.

    Plugin Support Riza Maulana Ardiyanto

    (@rizaardiyanto)

    Hi @holdench

    Please open a new discussion instead as per forums guideline so we can assist you with each case.

    Thanks,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Set unpublish data progamaticly’ is closed to new replies.