| @@ -70,11 +70,22 @@ | ||
| 70 | 70 | $this->end_controls_section(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | protected function get_dynamic_post_ID() { |
| 74 | - $latest_cpt = get_posts( "post_type=post&numberposts=1" ); | |
| 74 | + $post_type = 'post'; | |
| 75 | + $type = get_post_meta( get_the_ID(), '_templately_template_type', true ); | |
| 76 | + if($type == 'single') { | |
| 77 | + $post_type = 'post'; | |
| 78 | + } | |
| 79 | + else if($type == 'page_single') { | |
| 80 | + $post_type = 'page'; | |
| 81 | + } | |
| 82 | + else if($type == 'product_single') { | |
| 83 | + $post_type = 'product'; | |
| 84 | + } | |
| 85 | + $latest_cpt = get_posts( "post_type=$post_type&numberposts=1" ); | |
| 75 | 86 | |
| 76 | - return Plugin::$instance->editor->is_edit_mode() || isset( $_GET['preview_id'] ) || isset( $_GET['preview'] ) ? $latest_cpt[0]->ID : get_the_ID(); | |
| 87 | + return Plugin::$instance->editor->is_edit_mode() || isset($_GET['templately_library'], $_GET['preview_id']) ? $latest_cpt[0]->ID : get_the_ID(); | |
| 77 | 88 | } |
| 78 | 89 | |
| 79 | 90 | protected function render() { |
| 80 | 91 | static $did_posts = []; |
| @@ -82,9 +93,9 @@ | ||
| 82 | 93 | |
| 83 | 94 | $post = get_post(); |
| 84 | 95 | |
| 85 | 96 | // Avoid recursion |
| 86 | - if ( $post && isset( $did_posts[ $post->ID ] ) ) { | |
| 97 | + if ( isset($post, $post->ID) && isset( $did_posts[ $post->ID ] ) ) { | |
| 87 | 98 | return; |
| 88 | 99 | } |
| 89 | 100 | |
| 90 | 101 | $level ++; |
| @@ -89,10 +100,11 @@ | ||
| 89 | 100 | |
| 90 | 101 | $level ++; |
| 91 | 102 | $did_posts[ $post->ID ] = true; |
| 92 | 103 | // End avoid recursion |
| 104 | + Plugin::$instance->init_common(); | |
| 105 | + $is_edit_mode = Plugin::$instance->editor->is_edit_mode($post->ID); | |
| 93 | 106 | |
| 94 | - $is_edit_mode = Plugin::$instance->editor->is_edit_mode(); | |
| 95 | 107 | if ( $is_edit_mode || isset( $_GET['preview_id'] ) || isset( $_GET['preview'] ) ) { |
| 96 | 108 | echo get_the_content( null, null, $this->get_dynamic_post_ID() ); |
| 97 | 109 | |
| 98 | 110 | return false; |
| @@ -146,6 +158,11 @@ | ||
| 146 | 158 | |
| 147 | 159 | if ( 0 === $level ) { |
| 148 | 160 | $did_posts = []; |
| 149 | 161 | } |
| 162 | + } | |
| 163 | + | |
| 164 | + // getting infinite loop otherwise | |
| 165 | + public function render_plain_content() { | |
| 166 | + | |
| 150 | 167 | } |
| 151 | 168 | } |