Function to delete post from category older than 2 days

The get_posts() call is retrieving posts that were published after two days earlier. The after parameter retrieves posts after a certain date, and strtotime() is retrieving the date from two days ago.

Try changing after to before, and then change strtotime() first parameter to reflect your request. Researching the get_posts() and strtotime() functions will be helpful.

tech