Function Reference: geodir_get_term_icon

Summary

Gets term icon using term ID.

Description

If term ID not passed returns all icons.

Global Values

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

Default: None

Package

GeoDirectory

Parameters

$term_id
(int|bool) (required) The term ID.

Default: None
$rebuild
(bool) (required) Force rebuild the icons when set to true.

Default: None

Return Values

(mixed|string|void)
  • Term icon(s).

Change Log

Since: 1.0.0

Filters

‘geodir_get_term_icons’ [Line: 2084]

Source File

geodir_get_term_icon() is located in geodirectory-functions/taxonomy_functions.php [Line: 2026]

Source Code

function geodir_get_term_icon($term_id = false, $rebuild = false)
{
    global $wpdb;
    if (!$rebuild) {
        $terms_icons = get_option('gd_term_icons');
    } else {
        $terms_icons = array();
    }

    if (empty($terms_icons)) {
        $terms_icons = array();
        $default_icon_url = get_option('geodir_default_marker_icon');
        $taxonomy = geodir_get_taxonomies();
        $post_types = geodir_get_posttypes();
        $tax_arr = array();
        foreach ($post_types as $post_type) {
            $tax_arr[] = "'" . $post_type . "category'";
        }
        $tax_c = implode(',', $tax_arr);
        $terms = $wpdb->get_results("SELECT * FROM $wpdb->term_taxonomy WHERE taxonomy IN ($tax_c)");
        //$terms = get_terms( $taxonomy );

        if($terms) {
            foreach ($terms as $term) {
                $post_type = str_replace("category", "", $term->taxonomy);
                $a_terms[$post_type][] = $term;

            }
        }

        if($a_terms) {
            foreach ($a_terms as $pt => $t2) {

                foreach ($t2 as $term) {
                    $term_icon = geodir_get_tax_meta($term->term_id, 'ct_cat_icon', false, $pt);
                    if ($term_icon) {
                        $term_icon_url = $term_icon["src"];
                    } else {
                        $term_icon_url = $default_icon_url;
                    }
                    $terms_icons[$term->term_id] = $term_icon_url;
                }
            }
        }

        update_option('gd_term_icons', $terms_icons);
    }

    if ($term_id && isset($terms_icons[$term_id])) {
        return $terms_icons[$term_id];
    } elseif ($term_id && !isset($terms_icons[$term_id])) {
        return get_option('geodir_default_marker_icon');
    }

    if (is_ssl()) {
        $terms_icons = str_replace("http:","https:",$terms_icons );
    }

    return apply_filters('geodir_get_term_icons', $terms_icons, $term_id);
}