Where is the extra SQL fields coming from?

There is nothing wrong, the reason the data is there is to handle the problem of ordering when 2 posts have the same value for their meta key.

ORDER BY EventStartDate DESC, wp_posts.post_date DESC

Here we see that post data is not the only thing it’s ordering on, EventStartDate is what’s being ordered on, and those are defined at the beginning:

MIN(wp_postmeta.meta_value) as EventStartDate, 
MIN(tribe_event_end_date.meta_value) as EventEndDate

Which leads me to the conclusion that this SQL query is not the one for your WP_Query, but for another query entirely.

Additionally, if the end result is what you want, and the performance is good, then SQL used isn’t particularly relevant.


Upon further inspection, you’re trying to order by page views, but have used post meta is a means of storing page views. This leads to some problems:

  • every single page load has a DB write, this is awful for performance, the frontend should not make DB writes unless a user is logged in and filling out forms or setting things, especially not for simply viewing content
  • It’s incredibly unreliable. Updating the view count is not atomic, and there’s time between fetching the meta value and setting it. Opening the page in several tabs is enough to cause race conditions that result in under counting.
  • Caching pages is not possible, reducing performance, scalability, and acting as a negative hit to SEO

Use a 3rd party service or dedicated software to track this, then poll its APIs. E.g. Google Analytics or Jetpack stats