guys what I’m trying to do is run a series of if checks in the code before executing a series of functions and custom code. One of these if checks will check to see if a post already exists and if so it will then check how old the post is and if the post is say over 48 hours in age it will delete that post and recreate a new one.
Something to the effect of:
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 = age-of-post?
if $time >= 172800 // in seconds
code: delete the post and create a new one
else
$xtime = 172800 - $time;
echo 'You have already challenged' .$character. 'within the last 48 hours. You can challenge' .$character.'again in' .$xtime.'.';
I hope that sort of make sense. My question is how do you get the age-of-post and is there a function to delete a post already in wordpress? Or is there a simpler way to make posts go POOF after x amount of time?
You can use
wp_delete_post()
andget_the_date()
.I’m not sure of what you’re trying to do but why don’t you select the post_date in your request directly ?
You should then be able to test it in PHP (see this answer) and do what you want!