Remove duplication posts everywhere

Posted in: Newspaper
Post count: 25

Hi,

I’d like to not show duplicated posts on a same page for exemple if they are in a widget, big slide and so on I don’t want to see them appearing in the latest article, sidebar…

It will be good if you can implement that by default or through a global checkbox.

Please can you point me out where are all the files I should modify:

For the moment I found the class td_data_source and I did something like that

class td_data_source { 
function sow_exclude_duplicate() {
        global $wp_query;

        $EXCLUDE = $wp_query->posts;

        if (isset($EXCLUDE)) {
            $EXCLUDE_ID = array();

            foreach ($EXCLUDE as $post) {
                $EXCLUDE_ID[] = $post->ID;
            }

            return $EXCLUDE_ID;
        }
    }
}

   if (!empty($this->sow_exclude_duplicate())) {
            $args['post__not_in'] = $this->sow_exclude_duplicate();
        }

Please let me know,

Regards,

Fabien

Post count: 780

Can you give more details? This code works? You gave me a very cool idea. With your solution the code will prevent duplicate content on the whole page.

Radu from tagDiv

Post count: 25

Hi Radu,

Yes this works as I’m using it of all our websites, $args[‘post__not_in’] is one of the parameter for post and pages to http://codex.wordpress.org/Class_Reference/WP_Query

Basically I normally have one main function I use througout our sites where I pass all the parameter I need, in this case I get all the post id in a global variable from wquery then when another call is done for another component I exclude those Ids

The thing is with your theme I don’t know where all the things are and as I saw quickly you are not using a same function to fetch stuff with WPQuery.

This kind of might help you :


function sowGetPosts($options = array()) {
    $args = array();
    
    foreach ($options as $key => $value)
    {
            $key = strtoupper($key);
            $$key = $value;
    }

    if (!empty($EXCLUDE)) {
        $EXCLUDE_ID = array();

         foreach ($EXCLUDE as $post) {
             $EXCLUDE_ID[] = $post->ID;
         }

         $args['post__not_in'] = $EXCLUDE_ID;
    }
    
    if (isset($FROMCATEGORY)) {
        $cat = get_the_category();

        if (!empty($cat)) {
            $args['cat'] = $cat[0]->cat_ID;    
        }
    }
        
    $args['showposts'] = isset($LIMIT) ? $LIMIT : 5;
    
    $custom_query = new WP_Query($args);

    ...... and so on
    // If no articles get me the last 10
    if(!$custom_query->post_count) {
        sowGetPosts(array('EXCLUDE' => isset($posts) ? $posts : '',
                          'TITLE' => 'Latest Articles',
                          'LIMIT' => 10));
    }
   
    unset($custom_query);
    wp_reset_query();
}

Then I can use it eveywhere


sowGetPosts(array('FROMCATEGORY' => true,
                  'EXCLUDE' => $wp_query->posts,
                  ... and so on
            ));
  • This reply was modified 12 years by fgrenier.
Post count: 50

Please include this in the Theme core.

Post count: 13

Hello,

did you have implemented this code in last version 2.1.1?

It’s really useful and resolve the problem of duplicate post. I read your answer on ThemeForest comment, regard to resolve the problem when a post is featured, but between a specific category and recent/popular posts?

I don’t see other solutions.

Please, tell use if we can use this solution for the actual version of theme, and how insert it.

Thanks!

Post count: 3343

Hello,
This solution that @fgrenier provided us was not tested by us, still investigate if this will doable, we know that is a nice feature but we need more time for research.

We will update the roadmap topic on the forum with what will next up in the following updates, and work in progress.

Thanks for your message,
Marius from tagDiv

Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic.