WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to list just parent terms of a taxonomy (2 posts)

  1. jepser
    Member
    Posted 3 years ago #

    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

  2. jepser
    Member
    Posted 3 years ago #

    I added the parent=0 to the $args...

Topic Closed

This topic has been closed to new replies.

About this Topic