Important: duplicate posts on the page

This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!

Status: not resolved

Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #18281

      marcorroma
      Member

      Hi, some time ago you sent me a code to avoid duplicate posts on the page (built with WPbakery + Post block).
      The code works with all post blocks perfectly.
      I have a big problem with blocks with the “load more” button.
      Duplicates are displayed.
      And I can’t use offset, because I have various blocks in the page, example:
      block 1 with categories: ID 1 and ID 2
      block 2 with categories: ID 2 and ID 3
      block 3 with categories: ID 2, with “load more“.

      I can’t set a static offset in block 3, because in block 1 and block 2 there can be from 1 to 10 posts with category ID 2.

      can you help me? It is really important to me.
      I have worked hard to improve the page and now I am stopped.
      Thanks for support

      PS. the Code you sent me I think is this:

      add_action('parse_query', 'rfischmann__demo_exclude_duplicated_posts');
      
      $newsbeat__posts = array();
      
      function rfischmann__demo_exclude_duplicated_posts( $query ) {
          
          // Bait if is admin side or post type isn't post
      
          $post_type = $query->get( 'post_type' );
      
          if( is_admin() || 'post' !== $post_type )
              return;
      
          global $newsbeat__posts;
      
          $disable_now = $query->get('newsbeat__disable_edp' ); // use 'disable_edp' to prevent exclusion
      
          $exclude_posts = $newsbeat__posts;
      
          if( !$disable_now && !empty( $exclude_posts ) ){
              // We need to respect post ids already in the blacklist.
              $post__not_in = $query->get( 'post__not_in' );
      
              if ( ! empty( $post__not_in ) ) {
                  $exclude_posts = array_merge( (array) $post__not_in, $exclude_posts );
                  $exclude_posts = array_unique( $exclude_posts );
              }
      
              $query->set( 'post__not_in', $exclude_posts );
      
          }
      }
      
      add_filter('the_posts', 'rfischmann__demo_gathered_posts', 10, 2);
      
      function rfischmann__demo_gathered_posts( $posts, $query ) {
      
          $post_type = $query->get( 'post_type' );
          // Bait if is admin side or post type isn't post
          if( is_admin() || 'post' !== $post_type )
              return $posts;
      
          global $newsbeat__posts;
      
          foreach ($posts as $i => $post) {
              $newsbeat__posts[] = $post->ID;
      
          }
      
          return $posts;
      }
    • #18288

      marcorroma
      Member

      Hi Jacob, you replied. I see your message in email, but I don’t see your message in the thread.
      Anyway … I solved it.
      Thanks a lot.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.

This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!

© Copyright 2020 by wpthms.com. All Rights Reserved.