term_id)) {
return ‘category’;
}$term_id = intval($term->term_id);
$taxonomy = !empty($term->taxonomy) ? $term->taxonomy : ‘ai_category’;$icon = ”;
if (function_exists(‘get_field’)) {
$icon = get_field(‘category_dashicon’, $taxonomy . ‘_’ . $term_id);if (!$icon) {
$icon = get_field(‘category_dashicon’, ‘term_’ . $term_id);
}
}if (!$icon) {
$icon = get_term_meta($term_id, ‘category_dashicon’, true);
}if (!$icon) {
$icon = ‘dashicons-category’;
}$icon = sanitize_text_field($icon);
$icon = str_replace(‘dashicons-‘, ”, $icon);
$icon = sanitize_html_class($icon);return $icon ? $icon : ‘category’;
}/**
* Randomly get one Category Dashicon from ai_category.
*/
private static function get_random_category_dashicon() {
$terms = get_terms(array(
‘taxonomy’ => ‘ai_category’,
‘hide_empty’ => false,
‘number’ => 100,
));if (empty($terms) || is_wp_error($terms)) {
return ‘category’;
}shuffle($terms);
foreach ($terms as $term) {
$icon = self::get_category_dashicon_from_acf($term);if (!empty($icon)) {
return $icon;
}
}return ‘category’;
}/**
* Get random other AI Tags.
*/
private static function get_random_other_ai_tags($current_term_id, $limit = 5) {
$terms = get_terms(array(
‘taxonomy’ => self::TAXONOMY,
‘hide_empty’ => true,
‘exclude’ => array(intval($current_term_id)),
‘number’ => 80,
));if (empty($terms) || is_wp_error($terms)) {
return array();
}shuffle($terms);
return array_slice($terms, 0, intval($limit));
}/**
* Render random other AI Tag pills.
*/
private static function render_random_other_ai_tag_pills($current_term_id, $limit = 5) {
$tags = self::get_random_other_ai_tags($current_term_id, $limit);if (empty($tags)) {
return ”;
}ob_start();
?>