array('post', 'page'), 'post_status' => 'publish', 'p' => $_GET['id'] ); $the_query = new WP_Query($args); if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); ob_start(); include('pdf_template.php'); $template = ob_get_clean(); $mpdf = new \Mpdf\Mpdf(array( 'mode' => 'utf-8', 'format' => 'A4' )); $mpdf->WriteHTML($template); $mpdf->Output(); } } else { header('Location: '. get_bloginfo('url') . '123'); } } else { header('Location: '. get_bloginfo('url')); }