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'm using WP_Query() to pull out a few posts under a specific category "Featured" to display at the bottom of any post.

So I added <?php if (function_exists('getEditorPicks')) getEditorPicks();?> in single.php.

In functions.php, I have

    $args = array('cat' => 4176, 'posts_per_page' => 5);
    $query = new WP_Query($args);
    //return $query->query_vars;
    if ($query->post_count>2) {
        while ($query->have_posts()) {
            echo the_title();

However, it takes forever for the page to load now and it simply exhausts memory in the end.

What am I missing here?

share|improve this question
up vote 2 down vote accepted

should be:


The first is trying to fetch a property named the_post rather than invoking the function so the post never advances, and your loop is infinite.

share|improve this answer

In your codes you did not check if there exists any codes matching your query. So it is advisble to check first if query contains posts - $query->have_posts() - and then proceed.

You may have a look at the code here

share|improve this answer
Do not just post a link as an answer. Please post all relevant code and info from the link, and keep the link only as credit – Pieter Goosen Jul 13 '14 at 6:12
Strickly speaking, you only need the_post() on single pages. have_posts is not necessary, although it is advisable not to remove it as it may potensionally break plugins that hooks into this function – Pieter Goosen Jul 13 '14 at 6:19

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.