Support » Fixing WordPress » Multiple loop, querying some categories

  • I’m trying to generate posts from a given category creating 2 nested loops, therefore the main loop will be mixed up with some specific category posts. I’ve tried to hack the code Displaying ads after every third post without much luck so far.

    The trouble is that I have no control on the posts shown on the page. For instance, given the code below I get the same posts on a given page and most of the times on several pages.

    My goal is to loop through all the available posts in the category and show each of them twice on each page. When there are no more posts just not to show anything.

    This is the code I’m working on:

    $custom_query = new WP_Query('cat=176&posts_per_page=1&orderby=rand');
    
    while (have_posts()) : $ad_counter++; the_post();
    
    $ad_counter = $ad_counter % $after_every;
    
    while ($custom_query->have_posts()) : $custom_query->the_post();
    
                if(( 0 == $ad_counter)) {
    		//$do_not_duplicate[] = $post->ID;
    		//print_r($do_not_duplicate); ?>
    
    	  <article>//Looping</article>
    
          <?php }
          endwhile;
            wp_reset_query();

    Any help in the right direction will be greatly appreciated.

Viewing 1 replies (of 1 total)
  • esmi

    (@esmi)

    Forum Moderator

    Try:

    $custom_query = new WP_Query('cat=176&posts_per_page=1&orderby=rand');
    while ( $custom_query->have_posts() ) : $custom_query->the_post();
Viewing 1 replies (of 1 total)
  • The topic ‘Multiple loop, querying some categories’ is closed to new replies.