Context: In a social sharing plugin that I work on, I'm store social share counts in hidden post meta (custom fields) so that I can use that data for various functions around the plugin.
One useful use of this data is to create a Popular Posts widget that is based on the number of social shares that a post has. I use a query with the following arguments to accomplish this:
Example Code:
$swp_args = array(
'posts_per_page' => $count,
'post_type' => 'post',
'meta_key' => '_' . $network,
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
$swq = new WP_Query( $swp_args );
Where $count is a valid integer and $network is a valid name of one of the meta fields associated with the share count of a particular social network or the _totes field which reflects total shares across all networks.
The Problem: On 99% of sites, this query works spendidly and people think it's just the bees knees. However, on a small handful of sites, I've discovered some unusual behavior. In some instances, the widget never seems to update. For example, on the post itself, the post will reflect that it has 100 shares, but the widget will remain at 80 shares and continue to sort according to 80 shares. Both the post and the widget are using the exact same meta field for these functions.
The Question: What would cause the WP_query to continue returning outdated data? If it is some sort of caching, is there a way to force the query to not be cached but to always return fresh data from the database?