• Resolved Shereef Moussa

    (@shereefmoussa)


    Hi,
    (I am sorry if there is a grammar mistake)

    I am using the following code to avoid Duplicate posts. It works well with my query but not with pods template.

    add_filter('post_link', 'track_displayed_posts');
    add_action('pre_get_posts', 'remove_already_displayed_posts');
    
    $displayed_posts = [];
    
    function track_displayed_posts($url)
    {
       global $displayed_posts;
       $displayed_posts[] = get_the_ID();
       return $url; // don't mess with the url
    }
    
    function remove_already_displayed_posts($query)
    {
       global $displayed_posts;
       $query->set('post__not_in', $displayed_posts);
    }

    I tried to write in ‘where’ filed ‘t.ID NOT IN $displayed_posts’ but it did work. I think I could make an if statement inside of the template but I guess I will lose some post count. Is there away to avoiding Duplicate posts?

    Best regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @shereefmoussa

    Honestly, the where filter should work but it does depend on the way you format the conditional.

    NOT IN only supports array formatting.

    For example:

    t.ID NOT IN (1,2,3,4,5)

    So if you have an array of post ID’s you should do the following:

    't.ID NOT IN (' . implode( ',', $displayed_posts ) . ')'

    Cheers, Jory

    Thread Starter Shereef Moussa

    (@shereefmoussa)

    Hi @keraweb. How are you?

    I tried t.ID NOT IN (' . implode( ',', $displayed_posts ) . ')
    and t.ID NOT IN (' . implode( ',', global $displayed_posts ) . ')]
    IT didn’t cause an erorr but it Didn’t work neither.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘about avoiding Duplicate post using pods template’ is closed to new replies.