Getting the result/output of a template
-
Hello,
I am trying to get the output of a template file and save it as HTML. The following is my approach:
1) I have a page template, called page-template.php.
2) In my plugin.php I haveadd_action('edit_post', 'static_post'); add_action('publish_post', 'static_post'); function static_post($post_id){ $post_type = strtolower(get_post_type($post_id)); if($post_type == 'page'){ $template = get_post_meta( $post_id, '_wp_page_template' ); ob_start(); require_once(locate_template($template[0])); $contents = ob_get_contents(); custom_debug($contents); ob_end_clean(); } }
The custom_debug function writes the $contents to a .txt file for debugging.
3) The output is as follows:
Say the page-template.php contains<?php while(have_posts()): the_post(); ?> <h2><?php the_title(); ?></h2>
The output in the debug .txt file mentioned above is only
<h2></h2>
which means that the loop is not being executed. Or the query. I am not really sure.
Any suggestions? 🙂
Thank you
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Getting the result/output of a template’ is closed to new replies.