• Hello

    I need to create at least 3 loops in one template with post types, the first one is working perfectly, but when I place a second in the same template it doesn`t work correctly.

    – It should show 2 posts and shows only one;
    – Doesn′t print the information it should (and the first one does and I`m using the same code for both);
    – Also kills the <?php get_footer() ?> and if I try to get a sidebar;

    I`v tried to separate the code in a Get_template_part.. and the problem persists.

    This is the code I’m using for both loops changing only funcion names and args

    <?php
    
    $args = array(
    'post_type' => 'noticias',
    'posts_per_page' => 6
    
    );
    
    $noticias = new WP_Query ( $args );
    
    ?>
    
    <div class="row">
    
    <?php if (have_posts() ) : while( $noticias->have_posts()) : $noticias->the_post(); ?>
    
    <div class="small-12 large-4 columns">
    <div class="panel noticia-home-item">
    <div class="thumbtitle group">
    
    								<p><?php the_field( 'noticias' ); ?></p>
    <div class="thumbnail thumb-noticias-home">
    
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    </div>
    
    <h5>
    
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    
    <?php the_title(); ?>
    </a>
    </h5>
    
    <p class="data">Publicado em <?php $data = DateTime::createFromFormat('Ymd',get_field('data'));
    echo $data->format('d/m/y'); ?></p>
    
    <div class="resumo"><?php the_excerpt(); ?> </div>
    <div class="saiba-mais"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Saiba mais..</a></div>
    
    </div><!--thumb title-->
    </div><!--panel-->
    </div><!--large-4-->
    
    <?php endwhile; endif; ?>
    <?php wp_reset_postdata(); ?>
    
    </div><!--row-notícias-->

    The url is this – https://www.ufrgs.br/tsrs/telessauders/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try resetting the query after each of your WP_Query calls instead of wp_reset_postdata();

    https://codex.www.ads-software.com/Function_Reference/wp_reset_query

    try to enable DEBUG to see if you get any error messages – https://codex.www.ads-software.com/Debugging_in_WordPress

    even if you virtually use the same code for both loops, it might be useful if you could post the full code of the template here (or better via a pastebin – https://codex.www.ads-software.com/Forum_Welcome#Posting_Code )

    Thread Starter sandrabordini

    (@sandrabordini)

    Tried the wp_reset_postdata(); and it didn’t work
    will try the Debug

    Here`s the full code (there′s some static content, the loops are at the end):

    <?php get_header();
    
    /**
    *Template name: Home
    */
    
    ?>
    
    <div class="row destaque">
    <div class="small-12 large-12 columns linha-dourada"></div>
    <div class="row">
    <div class="small-12 large-3 columns newsletter"></div>
    <div class="small-12 large-6 columns destaque-0800"><div class="destaque-0800-interna"></div></div>
    		<div class="small-12 large-3 columns busca">
    			<?php get_search_form(); ?>
    
    		</div>
    	</div>
    </div>
    
    <div class="row slider">
    	<div class="small-12 large-12 columns">
    
    		<ul class="example-orbit" data-orbit>
    			<li>
    				<img src="../assets/img/examples/satelite-orbit.jpg" alt="slide 1" />
    				<div class="orbit-caption">
    				Caption One.
    				</div>
    			</li>
    			<li class="active">
    				<img src="../assets/img/examples/andromeda-orbit.jpg" alt="slide 2" />
    				<div class="orbit-caption">
    				Caption Two.
    				</div>
    			</li>
    			<li>
    				<img src="../assets/img/examples/launch-orbit.jpg" alt="slide 3" />
    				<div class="orbit-caption">
    				  Caption Three.
    				</div>
    			</li>
    		</ul>
    
    	</div>
    </div>
    
    <div class="row icones-servicos">
    
    			<div class="small-12 large-6 columns">
    				<div class="row"><!--teleconsultoria-->
    					<div class="small-12 large-12 columns titulo-teleconsultoria">TeleConsultoria</div><!--Parte dourada teleconsultoria-->
    						<div class="small-12 large-12 columns"><!--Servi?os teleconsultoria-->
    							<div class="row teleconsultoria">
    								<div class="small-4 large-4 columns vermelho"><div class="zero-oitocentos"><a href="#"></a></div></div>
    								<div class="small-4 large-4 columns azul"><div class="regulasus"><a href="#"></a></div></div>
    								<div class="small-4 large-4 columns verde"><div class="plataforma"><a href="#"></a></div></div>
    							</div>
    						</div>
    
    				</div>
    			</div>
    
    			<div class="small-12 large-6 columns">
    				<div class="small-4 large-4 columns"><!--apoio-->
    					<div class="titulo-apoio">Apoio</div>
    					<div class="apoio">
    						<div class="azul-escuro"><div class="info"><a href="#"></a></div></div>
    						<div class="azul-especial"><div class="nucleos"><a href="#"></a></div></div>
    					</div>
    				</div>
    				<div class="small-4 large-4 columns"><!--telediagnóstico-->
    					<div class="titulo-telediagnostico">TeleDiagnóstico</div>
    					<div class="telediagnostico">
    						<div class="amarelo-escuro"><div class="estomatonet"><a href="#"></a></div></div>
    						<div class="amarelo-medio"><div class="dermatonet"><a href="#"></a></div></div>
    						<div class="amarelo-claro"><div class="respiranet"><a href="#"></a></div></div>
    					</div>
    				</div>
    				<div class="small-4 large-4 columns"><!--desenvolvimento-->
    					<div class="titulo-desenvolvimento">Desenvolvimento</div>
    					<div class="rosa"><div class="desenvolvimento"><a href="#"></a></div></div>
    				</div>
    			</div>
    
    </div>
    
    <div class="row">
    	<div class="small-12 large-9 columns" role="main">
    
    	<h1>Notícias</h1>
    
    	<?php do_action( 'foundationpress_before_content' ); ?>
    
    		<?php
    
    			$args = array(
    				'post_type' => 'noticias',
    				'posts_per_page' => 6
    
    			);
    
    			$noticias = new WP_Query ( $args );
    
    		?>
    
    				<div class="row">
    
    				<?php if ($noticias->have_posts() ) : while( $noticias->have_posts()) : $noticias->the_post(); ?>
    
    					<div class="small-12 large-4 columns">
    						<div class="panel noticia-home-item">
    							<div class="thumbtitle group">
    
    								<div class="thumbnail thumb-noticias-home">
    
    									<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    								</div>
    
    								<h5>
    
    								<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    
    								<?php the_title(); ?>
    
    									</a>
    
    								</h5>
    
    								<p class="data">Publicado em <?php $data = DateTime::createFromFormat('Ymd',get_field('data'))
    										;
    									echo $data->format('d/m/y'); ?></p>
    
    								<div class="resumo"><?php the_excerpt(); ?> </div>
    								<div class="saiba-mais"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Saiba mais..</a></div>
    
    							</div><!--thumb title-->
    						</div><!--panel-->
    					</div><!--large-4-->
    
    				<?php endwhile; endif; ?>
    
    				<?php wp_reset_query(); ?>
    
    				</div><!--row-notícias-->
    
    	</div>
    
    	<h1>Vídeos Teleduca??o</h1>
    
    		<?php
    
    			$args = array(
    				'post_type' => 'videos',
    				'posts_per_page' => 2
    
    			);
    
    			$videos = new WP_Query ( $args );
    
    		?>
    
    				<div class="row">
    
    				<?php if ($videos->have_posts() ) : while( $videos->have_posts()) : $videos->the_post(); ?>
    
    			<div class="small-12 large-4 columns">
    						<div class="panel noticia-home-item">
    							<div class="thumbtitle group">
    
    								<div class="thumbnail thumb-noticias-home">
    
    									<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    								</div>
    
    								<h5>
    
    								<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    
    								<?php the_title(); ?>
    
    									</a>
    
    								</h5>
    
    								<p class="data">Publicado em <?php $data = DateTime::createFromFormat('Ymd',get_field('data'))
    										;
    									echo $data->format('d/m/y'); ?></p>
    
    								<div class="resumo"><?php the_excerpt(); ?> </div>
    								<div class="saiba-mais"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Saiba mais..</a></div>
    
    							</div><!--thumb title-->
    						</div><!--panel-->
    					</div><!--large-4-->
    
    				<?php endwhile; endif; ?>
    
    				<?php wp_reset_query(); ?>
    
    				</div><!--row-notícias-->
    
    </div>
    
    	<?php do_action( 'foundationpress_after_content' ); ?>
    
    </div>
    
    <?php get_footer(); ?>

    thank you for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can`t make more than one loop work in one template’ is closed to new replies.