Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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

share|improve this answer
add comment

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);
share|improve this answer
    
The first code is almost there except that I want to get the list of the id not the name. How do I do that? –  Mac Mendoza Aug 27 '13 at 6:26
    
Please try second one for your requirement –  Bindiya Patoliya Aug 27 '13 at 6:35
    
Ohh actually I was able to get the id using your first code. I just replaced the $terms->name with $term->term_id. –  Mac Mendoza Aug 27 '13 at 6:38
    
I'm editing a plugin with the code get_all_category_ids() and I know that the code above con't just replace the get_all_category_ids()... how will I be able to rewrite that code you have to be able to replace the get_all_category_ids()? –  Mac Mendoza Aug 27 '13 at 6:40
    
Use like this <?php $args=array( 'name' => 'Location' ); $output = 'objects'; // or objects $taxonomies=get_taxonomies($args,$output); if ($taxonomies) { foreach ($taxonomies as $taxonomy ) { echo '<p>' . $taxonomy->name . '</p>';echo '<p>' . $taxonomy->term_id. '</p>'; } } ?> –  Bindiya Patoliya Aug 27 '13 at 6:49
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.