Function Reference: geodir_diagnose_cats_sync
Summary
Syncs when categories are missing from the details table but showing in other places in the backend.
Description
Only checks posts with missing category info in details table.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Package
GeoDirectory
Change Log
Since: 1.0.0
Source File
geodir_diagnose_cats_sync() is located in geodirectory-admin/admin_hooks_actions.php [Line: 1276]
Source Code
function geodir_diagnose_cats_sync() { global $wpdb, $plugin_prefix; $fix = isset($_POST['fix']) ? true : false; //if($fix){echo 'true';}else{echo 'false';} $is_error_during_diagnose = false; $output_str = ''; $all_postypes = geodir_get_posttypes(); if (!empty($all_postypes)) { foreach ($all_postypes as $key) { // update each GD CTP $posts = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "geodir_" . $key . "_detail d WHERE d." . $key . "category='' "); if (!empty($posts)) { foreach ($posts as $p) { $p->post_type = $key; $raw_cats = wp_get_object_terms($p->post_id, $p->post_type . 'category', array('fields' => 'ids')); if (empty($raw_cats)) { $post_categories = get_post_meta($p->post_id, 'post_categories', true); if (!empty($post_categories) && !empty($post_categories[$p->post_type . 'category'])) { $post_categories[$p->post_type . 'category'] = str_replace("d:", "", $post_categories[$p->post_type . 'category']); foreach (explode(",", $post_categories[$p->post_type . 'category']) as $cat_part) { if (is_numeric($cat_part)) { $raw_cats[] = (int)$cat_part; } } } if (!empty($raw_cats)) { $term_taxonomy_ids = wp_set_object_terms($p->post_id, $raw_cats, $p->post_type . 'category'); } } if (empty($raw_cats)) { $post_cats = ''; } else { $post_cats = ',' . implode(",", $raw_cats) . ','; } $tablename = $plugin_prefix . $p->post_type . '_detail'; $wpdb->query($wpdb->prepare("UPDATE " . $tablename . " SET " . $p->post_type . "category=%s WHERE post_id =%d", $post_cats, $p->post_id)); } } $output_str .= "
- ";
echo $output_str;
echo $fix_button_txt;
echo "