Strange Wordpress Posts Display Issue

#1
Hi,
I’m having a really frustrating problem which I’ve spent days trying to fix. Basically I want to import data in CSV format into a Wordpress Custom Post Type.
However, after importing the data I noticed when I’m logged IN to WordPress the posts archive isn’t displaying all the posts and some posts are duplicated on the next page.
For example, the default amount of posts displayed per page for the Twenty Seventeen Theme is 10. If I import 15 posts, it will display a total of 15 posts, but it will displays posts 1 to 10 on page 1 and then posts 1 to 5 again on Page 2, so posts 11-15 are not displayed.
However, if I logout of WordPress OR increase the number of posts to display in the ‘Reading’ settings to 15 then all the posts display correctly.
The issue only occurs if I import data into the CPT not standard wordpress blog posts. However, after importing into the CPT it also effects the display of the standard WordPress Blog posts in the same way.
This still happens when the Litespeed Cache plugin is de-activated and/or deleted.

Things I’ve tried so far:
A fresh install of WordPress
De-activating all plugins and switching to Twenty Seventeen Theme
Adding CPT manually via functions file and also by using the CPT UI plugin
Tried 2 different Import plugins WP Awesome Import and WP All Import

My host have been looking into this but have not yet been able to find anything on the server stack that could be causing the issue. They only thing they have noticed is the import plugin gives every post the same timestamp which MAY be part of the cause.
I've also contacted the the developers of the WP All Import plugin and they say they have other customers that use Litespeed webserver with no issues. Also, they provided me with a sandbox server environment to test the import data with the same plugin and the issue doesn't occur there.
Surely there must be many Wordpress users that have to batch import data into Wordpress using a plugin and are on a Litespeed server. So in desperation can anyone advise me as to what I could suggest my host check in their configuration or anything else I could check myself?.
 

NiteWave

Administrator
#2
first you need confirm it's litespeed related issue.
ask your host to switch to apache for a short while, see if this issue also exists.
if still exists, it's likely a pure php/mysql issue, regardless web server being litespeed or apache or nginx.
 
#3
Hi NiteWave,
Thank you for your reply. They haven't tried apache but they have replied with this information:

"We have traced this to the queries below. The only difference is between the queries is "OR wo_posts.post_status = 'private'".

The issue itself simply looks to be due to the way the database orders the results when they all have the same post date.

As mentioned previously, you should amend the post dates if you want to order these yourself.

Logged in:
--------------------------------------------------------------------------------
Code:
MariaDB [table_name]> SELECT wo_posts.ID, wo_posts.post_date FROM wo_posts WHERE 1=1 AND wo_posts.post_type = 'post' AND (wo_posts.post_status = 'publish' OR wo_posts.post_status = 'private') ORDER BY wo_posts.post_date DESC LIMIT 0, 10;
+----+---------------------+
| ID | post_date |
+----+---------------------+
| 12 | 2018-06-04 13:59:04 |
| 13 | 2018-06-04 13:58:04 |
| 11 | 2018-06-04 13:58:04 |
| 10 | 2018-06-04 13:58:04 |
| 9 | 2018-06-04 13:58:04 |
| 8 | 2018-06-04 13:58:04 |
| 7 | 2018-06-04 13:58:04 |
| 6 | 2018-06-04 13:58:04 |
| 5 | 2018-06-04 13:58:04 |
| 4 | 2018-06-04 13:58:04 |
+----+---------------------+
10 rows in set (0.00 sec)
--------------------------------------------------------------------------------

Logged out:
--------------------------------------------------------------------------------
Code:
MariaDB [table_name]> SELECT wo_posts.ID, wo_posts.post_date FROM wo_posts WHERE 1=1 AND wo_posts.post_type = 'post' AND (wo_posts.post_status = 'publish') ORDER BY wo_posts.post_date DESC LIMIT 0, 10;
+----+---------------------+
| ID | post_date |
+----+---------------------+
| 12 | 2018-06-04 13:59:04 |
| 18 | 2018-06-04 13:58:04 |
| 17 | 2018-06-04 13:58:04 |
| 16 | 2018-06-04 13:58:04 |
| 15 | 2018-06-04 13:58:04 |
| 14 | 2018-06-04 13:58:04 |
| 13 | 2018-06-04 13:58:04 |
| 11 | 2018-06-04 13:58:04 |
| 10 | 2018-06-04 13:58:04 |
| 9 | 2018-06-04 13:58:04 |
+----+---------------------+
10 rows in set (0.00 sec)
--------------------------------------------------------------------------------

So my only option is to some how change/increment the post date for every post, but I need to import 10,000 posts so obviously I can't do that manually.
 
Last edited by a moderator:

NiteWave

Administrator
#4
"We have traced this to the queries below. The only difference is between the queries is "OR wo_posts.post_status = 'private'".
this is easy to understand though.
Logged in: wo_posts.post_status = 'publish' OR wo_posts.post_status = 'private'
Logged out: wo_posts.post_status = 'publish'
so logged in user can see posts with post_status='publish' + ''private'
while logged out user(guest) can see posts with post_status='publish' only.
this is reasonable and show the difference between logged in/out user.

while
how change/increment the post date for every post
is one option and looks difficult as you stated, another option is to modify the sql query statement (although I don't know where should be the right place)
from
Code:
ORDER BY wo_posts.post_date DESC LIMIT 0, 10
to
Code:
ORDER BY wo_posts.post_date DESC, wo_posts.ID DESC LIMIT 0, 10
so you'll always see consistent result.
and again, this is a pure php code issue.
 
#5
Yeh thanks for your help and suggestions. In the end I just added a post_date field to my CSV file and incremented each record by 1 second in my spreadsheet. I'm amazed there are not more reports of this issue but I didn't find any when googling. I do think Wordpress should change the default query to order by post_id though as you mentioned.
 
Top