From 84c1b53b5d4b57f5a5261796e65267feee616bf3 Mon Sep 17 00:00:00 2001 From: Filip Penkava Date: Fri, 17 Feb 2017 15:22:31 +0100 Subject: [PATCH] synchronize category, rename value form --- admin/admin.php | 6 ++--- autoload.php | 71 +++++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index 64fabdd..1f7d7e4 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -145,7 +145,7 @@ function mvp_admin() { - + diff --git a/autoload.php b/autoload.php index 803c021..40d14e1 100644 --- a/autoload.php +++ b/autoload.php @@ -26,6 +26,40 @@ if ($obj['type'] == 'text') { $guid = wp_strip_all_tags($obj['guid']); } + foreach ($obj['subject'] as $subject) { + if ($settings['subject-type'] == 'tags') { + $taxonomyTag[] = wp_strip_all_tags($subject['name']); + } elseif ($settings['subject-type'] == 'categories') { + $categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($subject['name']) . "'"); + + if ($categoryExist) { + $taxonomyCategory[] = $categoryExist->term_taxonomy_id; + } else { + $category_id = wp_insert_term(wp_strip_all_tags($subject['name']), 'category'); + $taxonomyCategory[] = $category_id['term_taxonomy_id']; + } + } + } + + if ($settings['convert-services'] == 'on') { + foreach ($obj['service'] as $service) { + $categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($service['name']) . "'"); + + if ($categoryExist) { + $taxonomyCategory[] = $categoryExist->term_taxonomy_id; + } else { + $category_id = wp_insert_term(wp_strip_all_tags($service['name']), 'category'); + $taxonomyCategory[] = $category_id['term_taxonomy_id']; + } + } + } + + if ($taxonomyCategory && !empty($taxonomyCategory)) { + $category = $taxonomyCategory; + } else { + $category = $settings['category']; + } + $sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'"); if ($sync) { @@ -35,7 +69,8 @@ if ($obj['type'] == 'text') { 'post_title' => wp_strip_all_tags($obj['headline']), 'post_name' => wp_strip_all_tags($obj['headline']), 'post_content' => $content, - 'post_content_filtered' => $content + 'post_content_filtered' => $content, + 'post_category' => $category ); wp_update_post($edit_post); @@ -81,40 +116,6 @@ if ($obj['type'] == 'text') { } - foreach ($obj['subject'] as $subject) { - if ($settings['subject-type'] == 'tags') { - $taxonomyTag[] = wp_strip_all_tags($subject['name']); - } elseif ($settings['subject-type'] == 'categories') { - $categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($subject['name']) . "'"); - - if ($categoryExist) { - $taxonomyCategory[] = $categoryExist->term_taxonomy_id; - } else { - $category_id = wp_insert_term(wp_strip_all_tags($subject['name']), 'category'); - $taxonomyCategory[] = $category_id['term_taxonomy_id']; - } - } - } - - if ($settings['convert-services'] == 'on') { - foreach ($obj['service'] as $service) { - $categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($service['name']) . "'"); - - if ($categoryExist) { - $taxonomyCategory[] = $categoryExist->term_taxonomy_id; - } else { - $category_id = wp_insert_term(wp_strip_all_tags($service['name']), 'category'); - $taxonomyCategory[] = $category_id['term_taxonomy_id']; - } - } - } - - if ($taxonomyCategory && !empty($taxonomyCategory)) { - $category = $taxonomyCategory; - } else { - $category = $settings['category']; - } - $postarr = array( 'post_title' => wp_strip_all_tags($obj['headline']), 'post_name' => wp_strip_all_tags($obj['headline']),