I figured out the problem.
Short answer:
Edit the content-expiration-and-redirect.php file. Replace line 59:
$id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name));
with the following:
$id = $query->queried_object->ID;
Long answer:
The reason it isn’t working is because when the page is expired you can’t retrieve the ID using get_the_ID()
. Instead, the author does a DB Query looking for a post name that matches the URL path. With the current setup, it will always work for posts and pages that use this format: https://www.sample.com/postname. However, if you have something like https://www.sample.com/category/postname, the query fails to find the post data and will always return a 404 error.
Luckily, the ID is already in the Query Object being used to retrieve the post name. It’s just hidden a little deeper. Using the line above you’ll always retrieve the correct ID, whether the page has expired or not.
I hope the author manages to update this soon. This is actually a really useful and easy to use plugin.
FYI: With this change line 58 ($name = isset...
) becomes unnecessary so that can be deleted too.