epl_listing_query_cache_ignores_meta_key: listing fields that don't refresh the search cache
Description #
When a listing field (post meta) is added, changed or removed, EPL refreshes the listing search cache. This filter decides which meta keys leave the cache as it is. By default hidden keys, starting with an underscore, are ignored, such as _edit_lock, which WordPress saves every minute while a listing is open in the editor. Use it to ignore a field your code updates often that the search never uses, or to make a hidden field you search on refresh the cache. See How the listing search cache works.
Usage #
add_filter( 'epl_listing_query_cache_ignores_meta_key', 'my_function', 10, 2 );
Parameters #
$ignore (bool)
True to leave the cache as it is. Default true for keys starting with an underscore, false for all others.
$meta_key (string)
The meta key that was added, changed or removed.
Examples #
A theme counts listing views in my_listing_views. It changes on every view and the search never uses it, so don't refresh the cache for it:
function my_epl_cache_ignores_view_count( $ignore, $meta_key ) {
if ( 'my_listing_views' === $meta_key ) {
return true;
}
return $ignore;
}
add_filter( 'epl_listing_query_cache_ignores_meta_key', 'my_epl_cache_ignores_view_count', 10, 2 );
A custom search field reads the hidden key _my_search_field, so changes to it should refresh the cache:
function my_epl_cache_watches_hidden_key( $ignore, $meta_key ) {
if ( '_my_search_field' === $meta_key ) {
return false;
}
return $ignore;
}
add_filter( 'epl_listing_query_cache_ignores_meta_key', 'my_epl_cache_watches_hidden_key', 10, 2 );
This only covers field changes. Saving a listing, changing its status or terms, or deleting it still refreshes the cache. Only listings (EPL listing post types) are checked; other posts never refresh it.
Source #
lib/includes/functions.php, in epl_listing_query_cache_ignores_meta_key(), called by epl_listing_query_cache_changed() on the added_post_meta, updated_post_meta and deleted_post_meta actions. Since 3.6.