WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I get an undefined Offset message with this Query. Can anyone Help?

$terms = get_the_terms( $post->ID , 'filters', 'string');
        $term_ids = wp_list_pluck($terms,'term_id');
        $second_query = new WP_Query( array(
              'post_type' => 'portfolio',
              'tax_query' => array(
                                'taxonomy' => 'filters',
                                'field' => 'id',
                                'terms' => $term_ids,
                                'operator'=> 'IN' //Or 'AND' or 'NOT IN'
              'posts_per_page' => 4,
              'ignore_sticky_posts' => 1,
              'orderby' => 'date',  // 'rand' for random order
           ) );
share|improve this question
If one of the answers solved your problem mark it as answer – click the checkmark on the left side. If not, ask for clarification. – toscho Oct 6 '12 at 22:08
He did ask for clarification and the answer poster never responded. – Tom Thorogood Mar 13 '13 at 12:32

When you use wp_list_pluck on $terms what you get is an array where the key is the same as the value. If you dump the contents of $term_ids you'll see something like:

    [42] => 42,
    [56] => 56

The code in query.php tries to reference the zero index of the term_ids array, but there is no index 0, hence the warning.

share|improve this answer
Okay, so what to do? :) I'm really not that advanced on this... :/ – Phil Sep 27 '12 at 18:30

As Milo pointed out your array is broken (the error told you that already). To get an array WP can work with use array_values():

$term_ids = array_values( wp_list_pluck( $terms,'term_id' ) );
share|improve this answer
Thanks a lot!! :-) – Phil Oct 10 '12 at 8:24

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.