Hide a Post by Displaying the 404 Error Page

Create a function which will check your condition. If the condition is met, set $wp_query->is_404 to true.

Then call that function like add_action(‘template_redirect’, ‘functionName’);

	function functionName()
            global $wp_query, $post;
            if (condition here) {
                    $wp_query->is_404 = true;

        add_action('template_redirect', 'functionName');



Share on FacebookShare on Google+Tweet about this on TwitterPrint this pageEmail this to someoneShare on Reddit

Leave a Reply