• Resolved plow0171

    (@plow0171)


    Hello,

    Is it possible to specify multiple posts when scheduling expiration programmatically?
    I want to get the post ID from the author ID and term and execute it.

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Riza Maulana Ardiyanto

    (@rizaardiyanto)

    Hi @plow0171

    This is only possible using a loop for each post you want to expire.

    Here is a snippet that look for specific user’s posts and schedule the expiration according to the arguments passed in the $opts array.

    <?php
    
    $timestamp = get_gmt_from_date('2022-11-01','U');
    $opts = [
        'expireType' => 'draft',
        'enabled' => true,
    ];
    
    $args = [
        'author' => $user_id,
        'orderby' => 'post_date',
        'order' => 'ASC',
        'posts_per_page' => -1 // no limit
    ];
    
    $user_posts = get_posts($args);
    
    foreach ($user_posts as $post) {
        postexpirator_schedule_event($post->ID, $timestamp, $opts);
    }
    Thread Starter plow0171

    (@plow0171)

    Hello,

    Thank you for the useful information.
    The program you informed me about worked well.

    Please also tell me how to remove the expiration date.

    I look forward to hearing from you.

    Plugin Support Riza Maulana Ardiyanto

    (@rizaardiyanto)

    Where do you want to remove the expiration date from? Please be more specific. If there is any screenshot, that would be helpful.

    Thread Starter plow0171

    (@plow0171)

    Hello,

    I want to programmatically delete all posts that match the author’s id.
    I tried the following code described on the homepage, but only one was deleted.

    if (function_exists(‘postExpirator_init’)) {
    $postId = 258;
    _unscheduleExpiratorEvent($postId);
    }

    Regards,

    Plugin Support Riza Maulana Ardiyanto

    (@rizaardiyanto)

    If we got it right, the logic will be the same. Just need to change the function from “schedule” to “unschedule”:

    <?php
    
    if (function_exists('postexpirator_unschedule_event')) {
        $args = [
            'author' => $user_id,
            'orderby' => 'post_date',
            'order' => 'ASC',
            'posts_per_page' => -1 // no limit
        ];
    
        $user_posts = get_posts($args);
    
        foreach ($user_posts as $post) {
            postexpirator_unschedule_event($post->ID);
        }
    }

    That will not delete the post itself, but will remove all the expiration settings for those posts, clean up the expiration data

    Thread Starter plow0171

    (@plow0171)

    Hello,

    Thank you for contacting us.
    The program you gave me worked fine.

    It was very helpful because I am not familiar with the program.
    I appreciate your help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to schedule an expiration date on multiple posts’ is closed to new replies.