You can use wp_delete_post()
and get_the_date()
.
global $wpdb;
if ( !is_user_logged_in())
echo 'You must be logged in.';
// check if title $my_post_name already exists in wpdb
else if ( is_user_logged_in()&& $wpdb->get_row("SELECT post_title FROM wp_posts WHERE post_title="" . $my_post_name . """, 'ARRAY_A')) {
// then check age of the post? assign age to a variable?
$time = get_the_date();
if ( $time >= 172800 ) // in seconds
wp_delete_post()
else
$xtime = 172800 - $time;
echo 'You have already challenged' .$character. 'within the last 48 hours. You can challenge' .$character.'again in' .$xtime.'.';