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.

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

wp_reset_postdata();
    $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()) {
            $query->the_post;
            echo the_title();
        }
    }
    wp_reset_postdata();

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
add comment

1 Answer

up vote 1 down vote accepted
$query->the_post;

should be:

$query->the_post();

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
add comment

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.