Support » Fixing WordPress » how to list just parent terms of a taxonomy

  • Resolved jepser

    (@jepser)


    Hi! I have a custom taxonomy named ‘ubicacion’, is hhierarchical and I have something like this:

    Guatemala
    -Guatemala City
    -Mixco
    – ….

    Sacatepequez
    -Antigua
    -Another item
    -…

    And so on, but I need just to list (in a select field) just the parents, I mean first level (guatemala, sacatepequez, etc).

    I’m using get_terms(); And this function:

    function get_terms_dropdown($taxonomies, $args){
    	$myterms = get_terms($taxonomies, $args);
    	$output ="<select name='".$taxonomies."'>";
    	foreach($myterms as $term){
    		$root_url = get_bloginfo('url');
    		$term_taxonomy=$term->taxonomy;
    		$term_slug=$term->slug;
    		$term_name =$term->name;
    		$link = $term_slug;
    		$output .="<option value='".$term_name."'>".$term_name."</option>";
    	}
    	$output .="</select>";
    return $output;
    }

    Any can help me please

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘how to list just parent terms of a taxonomy’ is closed to new replies.