PHP code example of alleyinteractive / expiring-posts

1. Go to this page and download the library: Download alleyinteractive/expiring-posts library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alleyinteractive / expiring-posts example snippets


expiring_posts_add_post_type(
	$post_type,
	[
		'action'       => 'draft',
		'expire_after' => MONTH_IN_SECONDS,
	],
);

expiring_posts_add_post_type(
	$post_type,
	[
		'action'       => 'trash',
		'expire_after' => WEEK_IN_SECONDS,
	],
);

expiring_posts_add_post_type(
	$post_type,
	[
		'action'       => 'delete',
		'expire_after' => WEEK_IN_SECONDS,
	],
);

expiring_posts_add_post_type(
	$post_type,
	[
		'action'       => 'update',
		'expire_after' => WEEK_IN_SECONDS,
		'update_args'  => [
			'meta_input' => [
				'key' => 'value',
			],
		],
	],
);

// Or use a callback to define the arguments. The callback
// is passed an instance of WP_Post.
expiring_posts_add_post_type(
	$post_type,
	[
		'action'       => 'update',
		'expire_after' => WEEK_IN_SECONDS,
		'update_args'  => fn ( WP_Post $post ) => [
			'post_title' => 'Expired: ' . $post->post_title,
		],
	],
);

expiring_posts_remove_post_type( $post_type );