• Resolved summerson

    (@summerson)


    Hi,
    My search is returning duplicates results.
    I’ve tried to use filter by id like :

    <? $oldID = 0; ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    	<? $currentID = $post->ID; ?>
    	<? if ($oldID == $currentID) { ?>
    
    // shows nothing if the ids are the same
    
    	<? } else { ?>
    
    // search result goes here 
    
            <? $oldID = $currentID; ?>
    	<? } ?>
    <?php endwhile; ?>
    <?php else : ?>
    No posts matched your search results.
    <?php endif; ?>

    but doesn’t work… enter in a infinity loop
    my code:

    <?php if ( have_posts() ) : ?>
        <div id="content-pages">
    		<?php while ( have_posts() ):?>
    		<div class="postagem-search">
    			<div class="titulo-post">
    			<a href="<?php the_Permalink();?>"> <?php the_title();?></a>
    		<?php the_post();?><a href="<?php the_Permalink();?>"><button type="button" class="btn btn-primary btn-sm pull-right">Continuar Lendo...</button></a>
    			</div>
    			<?php if(has_post_thumbnail()):?>
    			<div class="post-thumb">
    			<?php the_post_thumbnail();?>
    			</div>
    			<?php endif; // fim do if has_post_thumbnail?>
    			<?php  if (has_excerpt() ) : ?>
    			<div class="resumo-post">
    			<?php the_excerpt(); ?>
    			</div>
    			<?php endif; // fim do has_excerpt?>
                           </div> <!--fim da div postagem-search-->
    		<?php endwhile;?>

Viewing 1 replies (of 1 total)
  • Thread Starter summerson

    (@summerson)

    Hi,
    the solution above was correct.
    I’ll post the code if someone needs. I was putting the condition in a wrong place. correct way:

    <?php $idAntigo = 0;?>
    <?php if ( have_posts() ):?>
    <div id="content-pages">
    <?php while ( have_posts() ):the_post();?>
    <?php if( $post->ID == $idAntigo ){//show nothing}else{ // show the content of search?>
    <div class="postagem-search row">
    	<div class="titulo-post">
    		<a href="<?php the_Permalink();?>"> <?php the_title();?></a>
    	</div>
    	<?php if(has_post_thumbnail()):?>
    		<div class="post-thumb">
       			<?php the_post_thumbnail();?>
    		</div>
     	<?php endif; // fim do if has_post_thumbnail?>
    	<?php  if (has_excerpt() ) : ?>
    		<div class="resumo-post">
    			<?php the_excerpt(); ?>
    		</div>
    	<?php endif; // fim do has_excerpt?>
    	<a href="<?php the_Permalink();?>"><button type="button" class="btn btn-primary btn-sm">Continuar Lendo...</button></a>
    </div> <!--fim da div postagem-search-->
    <?php $idAntigo=$post->ID?>
    <?php };?>
    <?php endwhile;?>
    <?php echo next_posts_link('Proxima pagina');?>
    <?php echo previous_posts_link('Anterior');?>
    <?php else : ?>
    	<h4>Não foi encontrado resultado</h4>
    <p>Tente utilizando outra palavra-chave.</p>
    <?php endif; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘WP returns duplicates results on search’ is closed to new replies.