How to get term ID (6 posts)

  1. jepser
    Posted 5 years ago #

    I want to get the term ID to use it in get_term_children() in order to show them in a select.

    Anyone can tell me how to get the term ID based on the name of the term?

  2. jepser
    Posted 5 years ago #

    This is the thing I want to do, PLEASE HELP ME!

    I have a post-type name "Program" and "Curse" and both have a hierarchical configuration for a taxonomy named "Ubication", it has something like this:

    -Guatemala City
    -Antigua Guatemala
    -San Bartolomé

    I want a select field with the main tax terms i.e.(Guatemala and Sacatepequez)I got it with get_terms();

    Now I want to concatenate this main terms with their respective children, for example, if I choose "Guatemala", the second select will be auto-populate with Guatemala's children terms (Guatemala City, Mixco). So the deal is that I can't show the children terms.

    I'm trying to use get_term_children(), but I don't know how to use it and how to get the term ID.

    Please help me! :)

  3. chinmoy29
    Posted 5 years ago #

  4. jepser
    Posted 5 years ago #

    @chinmoy29 almost but I don't get any result,I use $term = get_term_by( 'slug', get_query_var( 'ingenieria' ), get_query_var( 'area' ) ); print_r($term);

    Any other suggestion?

  5. chinmoy29
    Posted 5 years ago #

    $term = get_term_by( 'slug', get_query_var( 'ingenieria' ), get_query_var( 'area' ) ); print_r($term);

    Your code is wrong. try this

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'texonomy' ) );

    Now you will get the result.

  6. getPressed
    Posted 4 years ago #

    Just a small typo to fix ("taxonomy" instead of "texonomy"):

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); print_r($term);

Topic Closed

This topic has been closed to new replies.

About this Topic