/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* Start non-duplicates */ function post_strip($where) { global $myPosts, $wpdb; $where .= " AND $wpdb->posts.ID not in($myPosts) "; return $where; } ?> <?php global $myPosts; $myPosts = ''; ?> <div> <?php $my_query = new WP_Query(); $my_query->query('showposts=5'); if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php $myPosts .= $post->ID . ","; ?> <div><?php the_title(); ?></div> <!-- Post Stuff --> <?php endwhile; endif; ?> </div> <?php $myPosts .= "0" ?> <?php add_filter('posts_where', 'post_strip'); ?> <div><br/> <?php //$my_query = new WP_Query('category_name=Life&showposts=15'); $my_query = new WP_Query('showposts=5'); while ($my_query->have_posts()) : $my_query->the_post();?> <div><?php the_title(); ?></div> <!-- Post Stuff --> <?php endwhile; ?> </div> <?php remove_filter('posts_where', 'post_strip'); ?> <?php /* End non-duplicates */ ?>
URL: http://w3updates.com/wordpress-tips-and-tricks-avoid-duplicate-posts/
Comments
