WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using Get Terms with the argument of 'name__like', how do i return all results that start with any number?

I've tried:

$feats = get_terms( 'movies', array('name__like' => '1', 'name__like' => '2', 'name__like' => '3' ) ); 


$feats = get_terms( 'movies', array('name__like' => '1,2,3,4,5,6,') ); 

Neither work properly. The first method will return the last "name__like" value but ignore the rest.

Any ideas?

share|improve this question
up vote 0 down vote accepted

Looking at the get_terms function definition, the value for name__like will be passed to the SQL query like:

" AND t.name LIKE '{$name__like}%'"

As such, I believe that you can only search for one of the numbers.

As an alternative strategy, you could iterate over the numbers you want to pull from the database:

$terms = array();
$numbers = range( 1, 6 );
foreach ( $numbers as $number )
    $terms[] = get_terms( 'movies', array( 'name__like' => $number ) );

As yet another alternative, you could make all of these terms that you want to get a child of another term. For instance, if you make a parent term called "Numbers", with id of 5, and assign all of the "numbered" terms as a child of this term, you could do:

get_terms( 'movies', array( 'parent' => 5 ) );

Obviously, the success of either strategy is dependent upon your use case. The first alternative is rather expensive, but with a nice caching strategy really shouldn't be an issue. The second method requires structuring data differently that may or may not work for your situation.

share|improve this answer
Thanks for the info. – Blackbird Feb 6 '12 at 9:57

Your Answer


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.