WordPress.org

Support

Support » How-To and Troubleshooting » How to get term ID

How to get term ID

  • Hi!
    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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
    -Guatemala City
    -Mixco
    Sacatepequez
    -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! 🙂

    @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?

    $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' ) );
    print_r($term);

    Now you will get the result.

    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);

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to get term ID’ is closed to new replies.