Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wordpress content doubling after first loop

Featured Replies

Hello, I have made a custom post type which has some posts.

 

However, after the first loop the content doubles. Here is the code (cut down):

<? query_posts('post_type=client_wall'); ?>

<?php while (have_posts()) : the_post(); ?>

<div class="client floatleft">
	<div class="client-title center-text georgia">
		<? the_title(); ?>
	</div>
	<div class="client-area">
		<div class="client-content floatleft georgia">
			<? the_content(); ?>
		</div>
		<div class="client-image floatright">
			<? the_post_thumbnail(); ?>
		</div>
	</div>
</div>

<?php endwhile;?>

 

Any reason this would be happening?

Edited by Alias

You say "the first loop" - if you're including multiple loops on a page, it's safest to instantiate a new WP_Query() for each rather than using query_posts, which just modifies and reruns the standard query for that page, assigning it to the standard $wp_query var.

 

$args = array(
 'post_type' => 'client_wall',
 );
$client_query = new WP_Query($args);
while($client_query->have_posts()) : $client_query->the_post();
<div class="client floatleft">
               <div class="client-title center-text georgia">
                       <?php the_title(); ?>
               </div>
               <div class="client-area">
                       <div class="client-content floatleft georgia">
                               <?php the_content(); ?>
                       </div>
                       <div class="client-image floatright">
                               <?php the_post_thumbnail(); ?>
                       </div>
               </div>
       </div>
<?php endwhile; ?>

 

 

Another way of doing it would be to back up and restore $wp_query before and after your custom loop:

 

<?php 
$temp = $wp_query;
query_posts('post_type=client_wall'); 
?>

<?php while (have_posts()) : the_post(); ?>

       <div class="client floatleft">
               <div class="client-title center-text georgia">
                       <?php the_title(); ?>
               </div>
               <div class="client-area">
                       <div class="client-content floatleft georgia">
                               <?php the_content(); ?>
                       </div>
                       <div class="client-image floatright">
                               <?php the_post_thumbnail(); ?>
                       </div>
               </div>
       </div>

<?php 
endwhile;
$wp_query = $temp;
?>

 

Couple of side points:

 

  1. Best not to use the short php opening tags. They might be supported on the host you're using, but a site may be moved to a different host in the future where they're not enabled.
  2. Your classes "center-text" and "georgia" are unsemantic - imagine the desired typeface changes in the future. Now elements with the class "georgia" are actually in Museo.

Edited by Renaissance-Design

  • Author

Ah thank you it worked :)

 

And yeah, didn't really think about that tbh, cheers! ^_^

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.