Home > AI > Backend > Wordpress >

get the category link by its name

function get_category_link_by_name($name, $wpdb) {
    $a = $wpdb->get_results( "SELECT t.*, tt.* FROM $wpdb->terms AS t
        INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
        WHERE tt.taxonomy = 'st_ai_cat' AND t.name = '$name'"
    );
    $cat_link = get_category_link($a[0]->term_id); 
    return $cat_link;
}

Leave a Reply