function pof_importer_tasksdriveimport_importRow($row, $row_index, $saveToDataBase = false) { $agegroups_and_taskgroups = pof_importer_get_agegroups_and_taskgroups(); if (empty($row['A']) || substr($row['A'], 0, 2) != 'KY' || empty($row['D'])) { if (!empty($row['D'])) { echo "Not importing, because row not setted to be imported: " . $row['D']; } else { if (empty($row['A'])) { return; } echo "Not importing, because row not setted to be imported, empty title. Row " . $row_index; } echo '<br />'; return; } echo "<br />"; echo "to be imported: " . $row['D']; /* echo "<pre>"; print_r($row); echo "</pre>"; */ $taskgroup_obj = new stdClass(); $agegroup_title = pof_importer_normalize_title($row['B']); $taskgroup_title = pof_importer_normalize_title($row['C']); if (!empty($agegroups_and_taskgroups[$agegroup_title]) && !empty($agegroups_and_taskgroups[$agegroup_title]->taskgroups[$taskgroup_title])) { $taskgroup_obj = $agegroups_and_taskgroups[$agegroup_title]->taskgroups[$taskgroup_title]; } if (empty($taskgroup_obj->id)) { echo "<h2>Couldn't find taskgroup '" . $row['C'] . "' for task '" . $row['D'] . "'</h2>"; return; } $wp_error = false; $post = null; $args = array('numberposts' => -1, 'posts_per_page' => -1, 'post_type' => array('pof_post_task'), 'meta_key' => 'suoritepaketti', 'meta_value' => $taskgroup_obj->id, 'search_post_title' => trim($row['D'])); add_filter('posts_where', 'pof_importer_title_filter', 10, 2); $the_query_task = new WP_Query($args); remove_filter('posts_where', 'pof_importer_title_filter', 10, 2); if ($the_query_task->have_posts()) { while ($the_query_task->have_posts()) { $item = new stdClass(); $the_query_task->the_post(); $post = $the_query_task->post; } } if (empty($post)) { echo " POST NOT FOUND; TO BE CREATED"; if ($saveToDataBase) { $post = array('post_title' => trim($row['D']), 'post_content' => $row['F'], 'post_type' => 'pof_post_task', 'post_status' => 'publish', 'post_author' => get_current_user_id()); $post_id = wp_insert_post($post, $wp_error); echo "imported, post_id: " . $post_id; $post = get_post($post_id); } } else { echo " POST FOUND; TO BE UPDATED"; $post_id = $post->ID; } if ($saveToDataBase) { update_post_meta($post_id, "suoritepaketti", $taskgroup_obj->id); update_field("ingress", $row['E'], $post_id); update_field("leader_tasks_fi", $row['G'], $post_id); $post->post_title = trim($row['D']); $post->post_content = $row['F']; $post->post_author = get_current_user_id(); update_post_meta($post_id, "task_duration", trim(str_replace(" min", "", $row['M']))); if (substr(strtolower($row['K']), 0, 2) == 'ky') { update_field("task_mandatory", 1, $post_id); } else { update_field("task_mandatory", 0, $post_id); } $places = pof_importer_get_places($row['L']); update_field("task_place_of_performance", $places, $post_id); update_field("task_level", pof_importer_get_level($row['N']), $post_id); echo " updated places, " . count($places) . " items,"; $skillareas = pof_importer_get_skillareas(trim($row['I'])); wp_set_post_terms($post_id, $skillareas, "pof_tax_skillarea", false); $growth_targets = pof_importer_get_growth_targets(trim($row['H'])); wp_set_post_terms($post_id, $growth_targets, "pof_tax_growth_target", false); update_post_meta($post_id, "content_imported_fi", pof_settigs_getDatetimeNow()); wp_update_post($post, $wp_error); } echo "<br />"; }
function pof_content_status_migration_growth_target_to_tag($post_id) { $content = trim(get_post_meta($post_id, "growth_target_fi", true)); if ($content != "") { $growth_targets = pof_importer_get_growth_targets(trim($content)); wp_set_post_terms($post_id, $growth_targets, "pof_tax_growth_target", false); update_post_meta($post_id, "growth_target_fi", ""); // update_field("growth_target_fi", "", $post_id); } }