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 am trying to get term ids from term name and cannot figure out why this code is not working.

$excludes = '';
    if($filtering_excludes) {

     $exclude_terms = explode(", ", $filtering_excludes);
        foreach ($exclude_terms as $exclude_term) {

            $term = get_term_by( 'name',  $exclude_term,  $filtering_tax  );
             $exclude_term = $term->term_id;         

        }

        $excludes= implode(", ", $exclude_terms);

    }

When I do a var_dump on $exclude_term is has the term id but $excludes is still returning the term name.

I have similar code for getting the category id from name and it works without a problem -- this is that code.

$excludes = '';
    if($filtering_excludes) {

     $exclude_cats = explode(", ", $filtering_excludes);
        foreach ($exclude_cats as &$exclude_cat) {
             $cat_id = get_category_by_slug($exclude_cat); 
            $exclude_cat = $cat_id->term_id;

        }

        $excludes= implode(", ", $exclude_cats);
    }

Can anyone see why my $exlcudes for terms is returning the name and not id?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Check for variables names:

  $excludes = '';
        if($filtering_excludes) {

         $exclude_terms = explode(", ", $filtering_excludes);
            foreach ($exclude_terms as $exclude_term) {

                $term = get_term_by( 'name',  $exclude_term,  $filtering_tax  );
                 $exclude_term_array[] = $term->term_id;         

            }

            $excludes= implode(", ", $exclude_term_array);

        }
share|improve this answer
    
Thank you, worked perfectly. –  ellenmva Feb 21 '13 at 17:06
add comment

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.