The block logs query does not override the count() method to give any kind of warning like the main query does, so it would seem that the count() method is intended to be usable. However, attempting to use it will produce a database error:
WordPress Database Error: Unknown column 'total' in 'order clause' [SELECT COUNT(*)
FROM `wptests_wordpoints_top_users_in_period_block_logs`
WHERE `user_id` = 5
GROUP BY `user_id`
ORDER BY `total` DESC
]
We need to prevent this by either giving a higher-level error and essentially disabling the method, or making the method work.
The issue is the ORDER BY clause, which references the total column. It isn't a column at all, but the sum of the points column, which we aren't calculating when we are just counting.
Probably the order clause can be omitted here, since it seems irrelevant to counting. Perhaps that should even be pulled upstream so that the order clause is always omitted from count queries. But regardless we'll need to fix this here in some way.
The block logs query does not override the
count()
method to give any kind of warning like the main query does, so it would seem that thecount()
method is intended to be usable. However, attempting to use it will produce a database error:We need to prevent this by either giving a higher-level error and essentially disabling the method, or making the method work.
The issue is the
ORDER BY
clause, which references thetotal
column. It isn't a column at all, but the sum of the points column, which we aren't calculating when we are just counting.Probably the order clause can be omitted here, since it seems irrelevant to counting. Perhaps that should even be pulled upstream so that the order clause is always omitted from count queries. But regardless we'll need to fix this here in some way.