Support » Plugin: 404page - your smart custom 404 error page » Doesn’t work with custom post status

  • Resolved Adrian

    (@adrian2k7)


    Hello,

    There is an issue with other plugins, which adds custom post status.

    The problem is, that not the custom 404 page is rendered, but the WordPress’/Themes default.

    You can use: VA Simple Expires
    This adds a new status “Ended”, which is a 404 for normal visitors.

    Thanks,

    Adrian

Viewing 7 replies - 1 through 7 (of 7 total)
  • Seems to be a general problem with posts with another status then publish, for instance “draft”.

    Then always the 404.php from the theme is used, instead the custom 404 page.

    Plugin Author Peter Raschendorfer

    (@petersplugins)

    Hi Adrian,

    seems to be a problem with your theme or with another plugin you’re using. I’ve installed VA Simple Expires plugin and it works as expected together with Twenty Seventeen theme and no other plugins active. It also works if I try to access a post with status draft.

    Could you please switch to default theme resp. deactivate all other plugins to figure it out.

    Peter

    This issue also exists in a site of a client of us. Draft URL’s are showing the standard WordPress 404 page when not logged in. This of course has to be the 404page plugin’s page.

    So, what I did to prevent this, is:

    404page.php line 77-83:

    $allDrafts = true;
    foreach($posts as $postt){
        if($postt->post_status != 'draft'){
            $allDrafts = false;
        }
    }
    if ( (empty( $posts ) || $allDrafts) && is_main_query() && !is_robots() && !is_home() && !is_feed() && !is_search() && !is_category() && !is_tax() &&( !defined('DOING_AJAX') || !DOING_AJAX ) ) {

    This checks the posts array whether there are posts that are not a draft. If this is the case, it wil skip the if and won’t show the 404. However, if the results in the array are all posts with post_status draft, the 404page will be shown.

    Plugin Author Peter Raschendorfer

    (@petersplugins)

    Damn, you are right. The post object is not empty when trying to access a draft post! A strange behavior. I’ll analyze how WP determines an 404 in case of trying to access a not published post directly.

    Thanks a lot for researching.

    Regards,
    Peter

    Plugin Author Peter Raschendorfer

    (@petersplugins)

    OK, that was a stiff piece of work, but I think I’ve found a solution that should work for all post states. I’ve tested it with about 30 different themes and it seems to work fine.

    @adrian2k7, @amazingwp would you please do me a favor and test the current development version which can be downloaded from https://downloads.wordpress.org/plugin/404page.zip?

    Thanks,
    Peter

    @petersplugins, that looks like some stiff piece of work indeed. I’ve just tested it and it seems to be working correctly! Thanks for fixing.

    Plugin Author Peter Raschendorfer

    (@petersplugins)

    Final version 2.4 is out now. Please confirm the issue is solved and the topic can be closed.

    Peter

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Doesn’t work with custom post status’ is closed to new replies.