• Resolved giant slayer

    (@giant-slayer)


    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

Viewing 1 replies (of 1 total)
  • Thread Starter giant slayer

    (@giant-slayer)

    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;

Viewing 1 replies (of 1 total)
  • The topic ‘WP_Query timing out.’ is closed to new replies.