WordPress.org

Ready to get started?Download WordPress

Forums

Second Loop of Multiloop Setup Only Visible When Logged In (3 posts)

  1. Roberto Villarreal
    Member
    Posted 3 years ago #

    Howdy,

    I have a multiloop setup working to display 2 separate categories of posts in 2 separate columns.

    The code works perfectly whenever you are logged in as an administrator, but it breaks and just shows duplicate posts for the second loop whenever you are logged out.

    Any advice? Any help is greatly appreciated!

    Here is the code:

    <!-- BEGIN LATEST NEWS -->
    	   <div id="latestNewsWrapper">
    		   	<div id="latestNewsTitle"><h1>Latest Tech News</h1></div>
    		   	<div id="latestNewsContent">
    				<?php
    				 $list = get_posts('category=tech-news&numberposts=3&order=DESC&orderby=DATE');
    				 foreach ($list as $post) :
    				    setup_postdata($post);
    				 ?>
    				<!-- Begin .postBox -->
    				<div class="postItem">
    
    						<h2><a>"><?php the_title(); ?></a></h2>
    						<div class="meta">
    									<?php the_time('M j, Y') ?>   //   by <span class="author"><?php the_author_link(); ?></span>   //    <?php the_category(', ') ?>   //   <?php comments_popup_link('No Comments', '1 Comment ', '% Comments'); ?>
    						</div>
    						<?php the_content(__('Read more >>')); ?> 
    
    				</div>
    			<!-- End .postBox -->
    			 <?php endforeach; ?>
    			 </div>
    	   	</div>
    	   	<!-- END LATEST NEWS -->
    	   	<!-- BEGIN LATEST TIP ENTRIES -->
    	   	<div id="latestTipsWrapper">
    		   	<div id="latestTipsTitle"><h1>Latest Tech Tips</h1></div>
    		   	<div id="latestTipsContent">
    		   		<?php
    				 $list = query_posts('category=tech-tips&numberposts=3&order=DESC&orderby=DATE');
    				 foreach ($list as $post) :
    				    setup_postdata($post);
    				 ?>
    				<!-- Begin .postBox -->
    				<div class="postItem">
    
    						<h2><a>"><?php the_title(); ?></a></h2>
    						<div class="meta">
    									<?php the_time('M j, Y') ?>   //   by <span class="author"><?php the_author_link(); ?></span>   //    <?php the_category(', ') ?>   //   <?php comments_popup_link('No Comments', '1 Comment ', '% Comments'); ?>
    								</div>
    						<?php the_content(__('Read more >>')); ?> 
    
    			</div>
    			<!-- End .postBox -->
    			 <?php endforeach; ?>
    			 </div>
    		</div>
    	   	<!-- END LATEST TIP ENTRIES -->
  2. Xephan
    Member
    Posted 3 years ago #

    To quote WordPress documentation

    The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page. If you want to create separate Loops outside of the main one, you should use get_posts() instead. Use of query_posts on Loops other than the main one can result in your main Loop becoming incorrect and possibly displaying things that you were not expecting.

    Ignoring that, the correct parameter should be category_name not category :)

  3. Roberto Villarreal
    Member
    Posted 3 years ago #

    Thanks very much. I changed category to category_name and it worked perfect. I then went on the change query_posts() to get_posts() and it is still working great.

    Thanks very much for your help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.