Skip Navigation

[Resolved] Duplication of Posts in Pagination

This support ticket is created 3 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 3 years, 12 months ago.

Assisted by: Minesh.

Author
Posts
#2091017

hidden link

When you click through the paginated results, some of the custom posts (Directory Listings) get repeated over and over rather than being only shown once in the results. It looks like its because of the random order sorting. Is there a way to make that apply to the entire set of posts rather than just the current page?

#2091317

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As you set your view to order by the random order, even when you paginate and move from one page to another page, the query will be fired is, for example:
show posts from 11 to 20 order by random order.

And random order will fetch any posts randomly.

With every page of pagination, Views will query the database, and get the results in random order as the view is set to order by random order and that is why you see the duplicated items in each page. There is no workaround available, you will have to remove random order.

#2092015

We have paid listings (approximately 100, so its not user-friendly to have them all on one page) and need to display people in an equitable way.

With that format of random it means that some people are never shown while others are shown multiple times. The pagination becomes useless.

Is there any other way we can display search results in an equitable way?

#2092225

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I think you should remove the order by random from your view's ordering section.

And use the following hook "wpv_filter_query_post_process" to randomize the found posts:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

For example:
- Try to add the following code to "Custom Code" section offered by Toolset or to your theme's functions.php file:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code

add_filter( 'wpv_filter_query_post_process', 'func_randomize_found_posts', 10, 3 );
 function func_randomize_found_posts( $query, $view_settings, $view_id ) {
    if ( $view_id == 9999 ) { 
         
        $query->posts  =   shuffle($query->posts);
        
    }
    return $query;
}

Where:
- Replace 9999 with your original view ID.