Forums

How to hide duplicated posts in a loop? (2 posts)

  1. JazzyPress
    Member
    Posted 1 year ago #

    Hi
    I have some duplicate posts issues on my website, and I can delete them using a cron job, but they still appears a couple hours before the cron delete them.

    I find an ugly solution for old wordpress versions describe here.
    But it doesn't work anymore.

    So I wondering if it's possible to simply hide posts which have same titles in a loop?

    here his my actual code to display posts :

    <?php
    
    $cat_args = array(
      'exclude_tree' => 1,
      'depth' => 1,
      'child_of' => 0,
    );
    
    $categories =   get_categories($cat_args); 
    
    foreach($categories as $category) {
    	if ($category->category_parent == 0) {
        echo '<li id="'.$category->cat_ID.'" class="'.$category->name.'"><div class="list-head"><h2><a>name.'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" '.'><img src="'.get_bloginfo("template_url").'/img/icon16.gif" class="'.$category->name.'" /><span>' . $category->name.'</span></a></h2></div>';
    	echo '<a href="void(0)"></a><a href="void(0)"></a><div class="paneflow"><div class="pane">
    <ul>';
    
         $post_args = array(
          'numberposts' => 20,
          'category' => $category->term_id
        );
    
        $posts = get_posts($post_args);
    
    	foreach($posts as $post) {
    
    	?>
    
    <li>
    			<!-- the posts -->
    
    <?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?>
    <?php the_title() ?>
    <?php the_excerpt(); ?>
    
    			<!-- the posts -->
    </li>
    	<?php }echo '</ul>
    </div></div>';
    	}
    }
    ?>

    What do you think?

    Thanks

  2. JazzyPress
    Member
    Posted 1 year ago #

    I saw a lot of thread related to Avoid duplicate posts in multiple loops by using the IDS.
    I hink it's maybe possible to use something like in one loop by using the title instead of the id.

Topic Closed

This topic has been closed to new replies.

About this Topic