0

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?

2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.