functions - Get list of all custom tanonomy id

admin2025-01-07  8

I created a custom taxonomy called Location then added New Jersey, New York, etc. Is there a Wordpress function that will get the list of all ids under the Location similar to what get_all_category_ids() does?

I created a custom taxonomy called Location then added New Jersey, New York, etc. Is there a Wordpress function that will get the list of all ids under the Location similar to what get_all_category_ids() does?

Share Improve this question asked Aug 27, 2013 at 6:04 Mac MendozaMac Mendoza 113 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You can get it like this

$terms = get_terms("my_taxonomy");
$count = count($terms);
if ( $count > 0 )
{
    echo "<ul>";
    foreach ( $terms as $term ) 
    {
        echo "<li>" . $term->name . "</li>";
    }
    echo "</ul>";
 }

Otherwise you can also use like this

$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$args_list = array(
   'taxonomy' => 'item', // or use $taxonomyName for all taxonomies
   'show_count' => true,
   'hierarchical' => true,
   'child_of' => $current_term->term_id,
   'hide_empty' => '0',
   'title_li' => '',
   'echo' => '0',
);
echo wp_list_categories($args_list);
<?php 
$args=array(
  'name' => 'Location'
);
$output = 'objects'; // or objects
$taxonomies=get_taxonomies($args,$output); 
if  ($taxonomies) {
    foreach ($taxonomies  as $taxonomy ) {

        $term = term_exists($taxonomy->name, 'Location');
            if ($term !== 0 && $term !== null) {
                echo '<p> TERM ID is -> ' .$term.'TERM NAME is ->'.  $taxonomy->name . '</p>';
            }
    }
}  
?>

try this :P

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261330a733.html

最新回复(0)