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.

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 );

unset($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

1 Answer 1

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.

$queryScience->the_post();

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

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.