Take the 2-minute tour ×

Im trying to get a list of post in a category with this:

$category = get_the_category();

$args = array( 
    'post_type'           => array('post', 'entrevista'),
    'cat'                 => $category[0]->term_id,
    'post__not_in'        => array(get_the_ID()),
    'ignore_sticky_posts' => 1,
    'posts_per_page'      => -1

$queryScience = new WP_Query( $args );


<?php if ( $queryScience->have_posts() ) : while ( $queryScience->have_posts() ) : ?>
    <option value="<?php echo get_permalink($queryScience->post->ID); ?>"><?php echo ucwords(get_the_date('M Y', $queryScience->post->ID)); ?></option>
<?php endwhile; endif; wp_reset_query(); wp_reset_postdata(); ?>

I think it goes infinity loop because shows more than 40.000 results. What am I doing wrong?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You have to call the_post() within your loop, otherwise you'll output the first post in an infinite loop, as have_posts() will always be true.


Also, you don't need wp_reset_query() with WP_Query, wp_reset_postdata() is enough.

share|improve this answer
Thanks you, I didn't know that =) –  Emanuel Feb 1 '13 at 19:58
add comment

Your Answer


