WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP_Query timing out. (2 posts)

  1. giant slayer
    Member
    Posted 2 years ago #

    On my single post, I am trying to add 6 additional images after the post which are in the same category. I created the query below which does return 6 random images from the same category as the post.

    However, for some reason the query is stuck in some type of infinite loop and eventually times out.

    Can anyone tell me what is going on with this query which would cause it to time out?

    $the_query = new WP_Query( array (
            'category_name'=>$category[0]->cat_name,
            'posts_per_page'=>'6',
            'post__not_in' =>array( $post->ID),
            'orderby' => 'rand'));
    while ( have_posts() ) : $the_query->the_post();
        the_post_thumbnail('random-6', array('class' => 'random-six'));
    endwhile;

    Thanks!!
    --christopher
    Here is a link to the page where you can see the time out.
    http://theviolent.net/inspirational/angels-are-watching

  2. giant slayer
    Member
    Posted 2 years ago #

    I got it figured out.
    I needed to add $the_query-> just before the have_posts.

    so the whole working code is as follows.

    $the_query = new WP_Query( array (
            'category_name'=>$category[0]->cat_name,
            'posts_per_page'=>'6',
            'post__not_in' =>array( $post->ID),
            'orderby' => 'rand'));
    while ( $the_query->have_posts() ) : $the_query->the_post();
        the_post_thumbnail('random-6', array('class' => 'random-six'));
    endwhile;

Topic Closed

This topic has been closed to new replies.

About this Topic