Custom post type single page returns 404 error

You should set your publicly_queryable argument to true when registering your custom post type. TAKE NOTE: Add flush_rewrite_rules(), refresh the page once or twice and REMOVE IT IMMEDIATELY. You SHOULD NOT keep flush_rewrite_rules() unless under the provisions as in the codex. this is an expensive operation so it should only be used when absolutely necessary

Redirect Restricted Page to 404

I was able to display a 404 error by using the following code in my header. <?php global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 ); exit(); ?> To break it down: $wp_query->set_404(): tells the wp_query this is a 404, this changes the title status_header(): sends a HTTP 404 header get_template_part(): displays the 404 template

How to create custom 401, 403 and 500 error pages?

Error pages are served up via .HTACCESS, if you are using Apache you would use the ErrorDocument directive and add the status and URL to it. So it would look like this in your .htaccess file: ErrorDocument 401 http://yourwebsite.com/error-401 ErrorDocument 403 http://yourwebsite.com/error-403 ErrorDocument 500 http://yourwebsite.com/error-500 You could use the following function below. This will dynamically … Read more

Are there any hooks that alter the 404 logic?

After a bit more slogging through code and Googling, I found the answer. It’s contained in this thread (see Otto42’s post), but for the record, adding the following to your plugin will override the 404 handling for the conditions you specify: add_filter(‘template_redirect’, ‘my_404_override’ ); function my_404_override() { global $wp_query; if (<some condition is met>) { … Read more

Cannot access non-wordpress subdirectories as wordpress overrides them with a 404 error

I’m assuming that you put WordPress in your site root and the external directories are also in your site root. The reason this is happening is that .htaccess files follow a hierarchy. Whatever directives are in the top-level .htaccess file flow down and apply to all directories below it. If this is the case, you … Read more

How to force a 404 on WordPress

You could try the WordPress function status_header() to add the HTTP/1.1 404 Not Found header; So your Code 2 example would be: function rr_404_my_event() { global $post; if ( is_singular( ‘event’ ) && !rr_event_should_be_available( $post->ID ) ) { global $wp_query; $wp_query->set_404(); status_header(404); } } add_action( ‘wp’, ‘rr_404_my_event’ ); This function is for example used in … Read more