'; $content['archive-template'] = ' '; return $content; } function documentor_import_template_content($fields, $content, $import_pages = array()){ global $pagelayer; $template_name = wp_get_theme(); $template_name = $template_name->template; $error = array(); foreach($fields as $fk => $fv){ if(empty($data[$fk])){ $fields[$fk]['post_content'] = $content[$fk]; $data[$fk] = $fields[$fk]; } } //for Pages foreach($data as $dk => $dv){ if(!empty($import_pages) && !isset($import_pages[$dk])){ continue; } $new_post = []; // Delete Old Data ? $args = array( 'post_type' => 'pagelayer-template', 'meta_query' => array( array( 'key' => 'documentor_imported_content', 'value' => $dk, 'compare' => 'EXISTS' ) ) ); $query = new WP_Query($args); if(!empty($query->posts)){ foreach ( $query->posts as $p ) { //echo $p->ID.'
'; $update_post['ID'] = $p->ID; $update_post['post_content'] = $dv['post_content']; wp_update_post($update_post); } continue; } // Make an array $new_post['post_content'] = $dv['post_content']; $new_post['post_title'] = $dv['title']; $new_post['post_name'] = $dk; $new_post['post_type'] = $dv['post_type']; $new_post['post_status'] = 'publish'; //r_print($new_post); // Now insert / update the post $ret = pagelayer_insert_content($new_post, $err); $post_id = $ret; if(empty($ret)){ $error[] = 'Could not update the page '.$dv['title']; continue; } if($dv['post_type'] == 'pagelayer-template'){ update_post_meta($post_id, 'pagelayer_template_type', $dv['type']); update_post_meta($post_id, 'pagelayer_template_conditions', $dv['conditions']); update_post_meta($post_id, 'documentor_imported_content', $dk); } } return $error; }