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 TwitterShare on LinkedInPrint this pageEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *