Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress two Loops on Index
    text
    copied!<p>What I am attempting to do is run two separate loops on my index page in Wordpress:</p> <p>One that does NOT HAVE posts from category 5</p> <p>And</p> <p>One that ONLY HAS posts from category 5</p> <p>I keep ending up with close to the right results but where the first loop shows what I want in the second loop (which baffles me) and a bunch of other anomalies.</p> <p>Here is the code:</p> <p>Loop 1:</p> <pre><code>&lt;?php $blogPreview = new WP_Query('cat=-5'); ?&gt; &lt;?php if ( $blogPreview-&gt;have_posts() ) : ?&gt; &lt;?php while ( $blogPreview-&gt;have_posts() ) : $blogPreview-&gt;the_post(); ?&gt; &lt;?php the_post(); ?&gt; &lt;?php get_template_part( 'content-index', get_post_format() ); ?&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; Sorry, but there are currently no posts in the blog! &lt;?php endif; ?&gt; &lt;?php wp_reset_query(); ?&gt; </code></pre> <p>Loop 2 (slightly below loop 1 in my markup):</p> <pre><code>&lt;?php $testimonials = new WP_Query('cat=5'); ?&gt; &lt;?php if ( $testimonials-&gt;have_posts() ) : ?&gt; &lt;?php while ( $testimonials-&gt;have_posts() ) : $testimonials-&gt;the_post(); ?&gt; &lt;?php the_post(); ?&gt; &lt;?php get_template_part( 'content-index-testimonials', get_post_format() ); ?&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; Sorry, but there are currently no posts in the blog! &lt;?php endif; ?&gt; &lt;?php wp_reset_query(); ?&gt; </code></pre> <p>Any Ideas? Thanks in advance</p> <p>Ok so that was fixed by removing "the_post()" from the loops.</p> <p>Now I cannot exclude this category for the life of me, I have tried all the following:</p> <pre><code>&lt;?php $blogPreview = new WP_Query('cat=-5'); ?&gt; &lt;?php $blogPreview = new WP_Query(array('category__not_in'=&gt;5)); ?&gt; &lt;?php $blogPreview = new WP_Query('category__not_in'=&gt;array(5)); ?&gt; </code></pre> <p>are all failing to do it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload