Verified Commit e6a3276e authored by Erick Hitter's avatar Erick Hitter
Browse files

Bypass all caching when retrieving jobs, otherwise duplicates may result

Like we do when checking if a job exists, retrieving jobs should also query directly to avoid caching such as what Advanced Post Cache provides.
parent 1d07e098
......@@ -201,26 +201,21 @@ class Cron_Options_CPT extends Singleton {
/**
* Retrieve list of jobs, respecting whether or not the CPT is registered
*
* `WP_Query` also can't be used before `init` due to capabilities checks
* Uses a direct query to avoid stale caches that result in duplicate events
*/
private function get_jobs( $args ) {
// If called before `init`, we need to query directly because post types aren't registered earlier
if ( did_action( 'init' ) ) {
return get_posts( $args );
} else {
global $wpdb;
$orderby = 'date' === $args['orderby'] ? 'post_date' : $args['orderby'];
global $wpdb;
if ( isset( $args['paged'] ) ) {
$paged = max( 0, $args['paged'] - 1 );
$offset = $paged * $args['posts_per_page'];
} else {
$offset = 0;
}
$orderby = 'date' === $args['orderby'] ? 'post_date' : $args['orderby'];
return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s ORDER BY %s %s LIMIT %d,%d;", $args['post_type'], $args['post_status'], $orderby, $args['order'], $offset, $args['posts_per_page'] ), 'OBJECT' );
if ( isset( $args['paged'] ) ) {
$paged = max( 0, $args['paged'] - 1 );
$offset = $paged * $args['posts_per_page'];
} else {
$offset = 0;
}
return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s ORDER BY %s %s LIMIT %d,%d;", $args['post_type'], $args['post_status'], $orderby, $args['order'], $offset, $args['posts_per_page'] ), 'OBJECT' );
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment