Have a method to get cache_key from object id?
-
It would be great to have a method to get cache_key from object id, so we can avoid custom functions like the one below. What do you think? Does it already exists? Thanks
function hm_getPostCacheKeys($postID){ global $wpdb; $sql = "SELECT <code>cache_id</code> FROM .<code>{$wpdb->prefix}wrc_relations</code> WHERE <code>object_id</code> = %s LIMIT %d"; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $caches = $wpdb->get_results( $wpdb->prepare( $sql, $postID, 1 ) ); if (!isset($caches) || empty($caches)) return false; $keys = Array(); foreach ( $caches as $cache ) { $sql = "SELECT <code>cache_key</code> FROM <code>{$wpdb->prefix}wrc_caches</code> WHERE <code>cache_id</code> = %s "; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $cachesKeys = $wpdb->get_results( $wpdb->prepare( $sql, $cache->cache_id) ); if ($cachesKeys){ foreach ( $cachesKeys as $key ) { $keys[] = $key->cache_key; } } } return $keys; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Have a method to get cache_key from object id?’ is closed to new replies.