In your first sentence i’m assuming you mean, you have a Custom Post Type (not time).
So the post has a package connected, the package has a number of days alive setting. Reading your example code, i think you’re approaching this from the wrong angle.
I would do something like this:
// I don't know how you want to call this function, i would use a daily cron-job
function remove_expired_posts() {
$current_date = new DateTime();
$args = array(
'posts_per_page' => -1,
'post_type' => 'YOUR_CUSTOM_POST_TYPE_NAME_HERE',
'post_status' => 'publish',
);
$posts = get_posts( $args );
if($posts) {
foreach($posts as $post) {
$post_id = $post->ID;
$post_date = DateTime::createFromFormat('Y-m-d H:i:s', $post->post_date');
$package_id = get_post_meta( $post_id, 'package_select', true );
$transaction_price_pkg = $monetization->templ_get_price_info( $package_id, '' ); // make sure you include the $monetization object
$alive_days = (int)$transaction_price_pkg[0]['alive_days'];
$expire_date = $post_date->modify('+ '.$alive_days.' days');
if($current_date > $expire_date) {
wp_delete_post( $post_id, true ); // true means bypass bin.
}
}
}
}
NOTE:
I haven’t tested this code, but it should work. At least it should give you an idea how to go forward with this.
Regard, Bjorn