Really old events shows as upcoming, bug in WordPress' generated SQL
-
Hi,
I’m porting a site to WordPress and it contains some lists of events going back to the late 1990s (and a couple of misdated ones that show up as happening on January 1st 1970 but let’s ignore those..)My problem is that using the normal vsel shortcode, many of the really old events appear as if they were upcoming ones.
I’ve spent a bit of time on this, gone as far as trying to debug the SQL generated by WordPress:
cur2.execute("SELECT SQL_CALC_FOUND_ROWS wp_site_posts.ID FROM wp_site_posts INNER JOIN wp_sisu_no_postmeta ON ( wp_site_posts.ID = wp_sisu_no_postmeta.post_id ) INNER JOIN wp_sisu_no_postmeta AS mt1 ON ( wp_site_posts.ID = mt1.post_id ) WHERE 1=1 AND ( wp_sisu_no_postmeta.meta_key = 'event-date' AND ( ( mt1.meta_key = 'event-date' AND CAST(mt1.meta_value AS CHAR) >= '1456272000' ) ) ) AND wp_site_posts.post_type = 'event' AND ((wp_site_posts.post_status = 'publish')) GROUP BY wp_site_posts.ID ORDER BY wp_sisu_no_postmeta.meta_value+0 ASC LIMIT 0, 10")
Note that CAST(mt1.meta_value AS CHAR)? Turns out that string comparisons of numerical timestamps can give you weird results. See:
MariaDB [site_db]> select 907884000 >= 1456272000; +-------------------------+ | 907884000 >= 1456272000 | +-------------------------+ | 0 | +-------------------------+ 1 row in set (0.00 sec) MariaDB [site_db]> select '907884000' >= '1456272000'; +-----------------------------+ | '907884000' >= '1456272000' | +-----------------------------+ | 1 | +-----------------------------+ 1 row in set (0.00 sec)
This appears to be why events that are so old their time stamp string are shorter (but starts with a higher number) actually appear as future events. The >= operator doesn’t do what you expect when comparing strings instead of numbers.
https://www.ads-software.com/plugins/very-simple-event-list/
- The topic ‘Really old events shows as upcoming, bug in WordPress' generated SQL’ is closed to new replies.