How do you get the path of a taxonomy term by it's tid. I am getting the taxonomy title and tid from the database, but I cannot figure out how to link it to its page. Any pointers?

Comments

nevets’s picture

If you have a term object you can use taxonomy_term_path().

njguy’s picture

I have tried that but it doesn't give me the right path. It only ever returns this, "taxonomy/term/".

nevets’s picture

Did you pass it a term object? (Like that return by taxonomy_get_term($tid))

njguy’s picture

yes I passed it a term id.

$termpath = taxonomy_term_path($term);

$term is the id selected from the database.

njguy’s picture

It worked when I did this, but I'm not getting the pathauto url.

$termobj = taxonomy_get_term($term);
$termpath = taxonomy_term_path($termobj);

nevets’s picture

Pass $termpath to l() if you want a link or url() if you want a path.

njguy’s picture

Thanks so much, that's exactly what I needed.

loopduplicate’s picture

// first, get a term object from a term ID
$term = taxonomy_get_term($tid);
// then, use the term object to get the unaliased path
$taxonomy_path = taxonomy_term_path($term);
// finally, lookup the path alias using drupal_lookup_path()
$taxonomy_path_alias = drupal_lookup_path('alias', $taxonomy_path);
nevets’s picture

If you feed $taxonomy_path to either l() or url() there is no need to look up the alias.

jack-pl’s picture

For Drupal 7 you can use: taxonomy_term_uri()

$term = taxonomy_term_load($tid); // load term object
$term_uri = taxonomy_term_uri($term); // get array with path
$term_title = taxonomy_term_title($term);
$term_path = $term_uri['path'];
$link = l($term_title,$term_path);
shashwat purav’s picture

Thank you jack-pl. This is helpful.

Thank You,
Shashwat Purav

Chim’s picture

url('taxonomy/term/' . $tid);

featherbelly’s picture

drupal_get_path_alias('taxonomy/term/' . $tid)

drupal_get_path_alias

hanna21’s picture

maybe this will help as it helped me

function get_term($tid) {
  return db_select('taxonomy_term_data', 't')
  ->fields('t', array('name'))
  ->condition('tid', $tid)
  ->execute()
  ->fetchField();
}
$term = taxonomy_term_load($tid);
$name = $term->name;
$tids = array(1, 2, 3);
$terms = taxonomy_term_load_multiple($tids);

foreach ($terms as $term) {
  $name = $term->name;
}
boss041’s picture

Hi,

Suspicious activity found in my drupal website. Drupal version is 7.61

suspicious activity onto the firewall based on real time attacks in form of China Chopper & Obfuscated.Rich.Text.Format.

Attack  Description     Recommendation
Bash.Function.Definitions.Remote.Code.Execution This indicates an attack attempt to exploit a Remote Code Execution vulnerability in Bash.

The vulnerability is due to insufficient sanitizing of user supplied inputs in the application. A remote attacker may be able exploit this to execute arbitrary code within the context of the application.     Upgrade to the latest version available from the website.

How to fix the issue ?