Function Reference: geodir_update_markers_oncatedit

Summary

Update markers on category Edit.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$plugin_prefix
(string) (required) Geodirectory plugin table prefix.

Default: None

Package

GeoDirectory

Parameters

$term_id
(string) (required) The term ID as string.

Default: None
$tt_id
(int) (required) The term taxonomy ID.

Default: None
$taxonomy
(string) (required) The taxonomy slug.

Default: None

Change Log

Since: 1.0.0

Source File

geodir_update_markers_oncatedit() is located in geodirectory-functions/post_functions.php [Line: 2727]

Source Code

function geodir_update_markers_oncatedit($term_id, $tt_id, $taxonomy)
{
    global $plugin_prefix, $wpdb;

    $gd_taxonomies = geodir_get_taxonomies();

    if (is_array($gd_taxonomies) && in_array($taxonomy, $gd_taxonomies)) {

        $geodir_post_type = geodir_get_taxonomy_posttype($taxonomy);
        $table = $plugin_prefix . $geodir_post_type . '_detail';

        $path_parts = pathinfo($_REQUEST['ct_cat_icon']['src']);
        $term_icon = $path_parts['dirname'] . '/cat_icon_' . $term_id . '.png';

        $posts = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT post_id,post_title,post_latitude,post_longitude,default_category FROM " . $table . " WHERE FIND_IN_SET(%s,%1\$s ) ",
                array($term_id, $taxonomy)
            )
        );

        if (!empty($posts)):
            foreach ($posts as $post_obj) {

                $lat = $post_obj->post_latitude;
                $lng = $post_obj->post_longitude;

                $json = '{';
                $json .= '"id":"' . $post_obj->post_id . '",';
                $json .= '"lat_pos": "' . $lat . '",';
                $json .= '"long_pos": "' . $lng . '",';
                $json .= '"marker_id":"' . $post_obj->post_id . '_' . $term_id . '",';
                $json .= '"icon":"' . $term_icon . '",';
                $json .= '"group":"catgroup' . $term_id . '"';
                $json .= '}';

                if ($post_obj->default_category == $term_id) {

                    $wpdb->query(
                        $wpdb->prepare(
                            "UPDATE " . $table . " SET marker_json = %s where post_id = %d",
                            array($json, $post_obj->post_id)
                        )
                    );
                }

                $wpdb->query(
                    $wpdb->prepare(
                        "UPDATE " . GEODIR_ICON_TABLE . " SET json = %s WHERE post_id = %d AND cat_id = %d",
                        array($json, $post_obj->post_id, $term_id)
                    )
                );

            }


        endif;

    }

}