Forums › Forums › Search & Filter Pro › Duplicate search results
Tagged: duplicates
- This topic has 17 replies, 3 voices, and was last updated 6 years, 6 months ago by Anonymous.
-
Ross Moderator(Private) May 9, 2018 at 9:23 pm #176753
Hi David
I’ve had another look into this, and I have some feedback.
First, you should be able to resolve your issue by setting a secondary sort option in the
posts
tab of your search form 🙂Second, to explain how this works (if you’re interested):
A lot of your posts, while sharing a publish date, also share the exact same publish time (I guess these were added programatically in some way, or their publish date/time was modified somehow).
Just to clarify, if you don’t choose a sort order, WP default is by date, which is why I mention the identical dates.
Anyway, there seems to be a little quirk in WP WP_Query class, or perhaps in the SQL itself – which meant that simply changing pagination in the exact exact same query, meant the posts were ordered in a different way, after being ordered by date first.
To demonstrate, I created a WP query, which specified which post IDs I wanted (the twenty from the examples we’ve been using, your IDs may be different but I did import your classes post type locally)
<?php $args = array( 'post_type' => 'classes', 'paged' => '1', 'posts_per_page' => '12', 'post_status' => array('publish'), 'post_type' => 'classes', 'orderby' => array("post_date" => "DESC"), 'post__in' => array(9111,9117,9121,9143,9144,9145,9146,9147,9148,9149,9150,9151,9152,9328,9347,9359,9360,9363,9365,9366) //, ); $query = new WP_Query($args); $results = $query->get_posts(); foreach ($results as $post) { //var_dump($post); echo "{$post->ID} | {$post->post_title}<hr />"; } ?>
Of course the issue is when 2 or more posts share identical publish dates/times, what order do they appear in?
If you run this test and change pagination to 2, you will see the exact issue you have been experiencing – where the secondary sorting is inconsistent when changing pagination..
Therefor the solution is that if we specify a secondary sort option, we control the consistency of the order.
Anyway, hope all that helps!
Thanks
Anonymous(Private) May 9, 2018 at 10:24 pm #176758Ross this is awesome and I appreciate the detailed explanation. Many posts were indeed imported programmatically and the unique publish dates must not have been brought order. Secondary sorting by title is doing the trick.
Thanks again for troubleshooting.
-
AuthorPosts