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.

My custom query works, but in debugging mode I get this error:

Notice: Undefined offset: 0 in /storage/content/24/150624/mydomain.com/public_html/wp/mysite/wp-includes/query.php on line 2232 

This is what my query looks like:

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

<?php 
global $post;

$args = array(
'tax_query' => array(
array(
    'taxonomy' => 'machinecategory',
    'terms' => $term,
    'field' => 'slug',
    'operator' => 'IN'
)
),
'posts_per_page' => -1,
'post_type' => 'machine',
);

$my_query = new WP_Query($args); ?>
<?php if ($my_query->have_posts()) : ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_title();?> 
<?php endwhile; ?>
<?php endif;?>

<?php wp_reset_query(); ?>

What could be wrong?

share|improve this question
2  
where do you set $term? –  Milo Jun 20 '12 at 13:51
    
I forgot to paste it in, edited my post. It seems to be working, I only get posts with the correct term. –  Johan Dahl Jun 20 '12 at 14:04

1 Answer 1

up vote 2 down vote accepted

get_term_by returns an object, try passing $term->slug to your query instead.

share|improve this answer
    
That worked, thank you! –  Johan Dahl Jun 20 '12 at 15:19

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.