• My users create posts with links to future posts which are in Draft status. We use Post Name as our permalink structure.

    As usual, when these users click such links they are directed to the Drafts for editing. Eg.

    <a href="/future-draft-post">Here is our next fantastic post!</a>

    And also as usual, when non-logged-in users click such a link they get a 404.

    What I want is for non-logged-in users to click such a link and instead of getting a 404 be redirected to a custom page that says ‘Coming Soon!’

    How do I do that?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Requesting a future post does not result in a true 404 error, rather it causes the “Not Found” portion of your theme’s templates to display. This is the part after the main loop that is used when no posts are returned. Typically the else: part of if ( have_posts() ) : Every theme manages this a little differently, so I cannot be too specific. Adding to the confusion, some themes use a 404.php template for this even though it is not a true 404 error. Other themes have a special template for this. twentysixteen uses /template-parts/content-none.php for this.

    Once you’ve identified the correct template code for your theme, create a child theme and copy this template to the child’s folder. Edit the “Not Found” and whatever other related content you want changed.

    The problem here is the new “Coming Soon” message is displayed for both future posts and posts that truly do not exist. To differentiate between the two will require another query for the post name, this time where the status is “future”. You can use get_posts() for this. Note that a future scheduled post and a draft post are not the same thing. If a post is returned this time, it is safe to output a “Coming Soon” message, otherwise it’s a bad request and “Not Found” is more appropriate.

Viewing 1 replies (of 1 total)
  • The topic ‘Redirecting links to Draft Posts to custom page’ is closed to new replies.