apply_filters( 'relevanssi_cached_post_object', stdClass $post )
Filters the post objects as they are cached.
Parameters
$post
(stdClass) The post object from wp_posts
database table.
More information
When Relevanssi searches, it caches the post objects it finds to reduce the number of database queries. These post objects are taken from the wp_posts
database table with $wpdb->get_results()
, which generates stdClass
objects instead of WP_Post
objects.
Most of the time, this doesn’t matter. However, if your site is built to check the types and to expect WP_Post
objects, this will cause trouble. Relevanssi can’t cache WP_Post
objects – it has been tried and causes out-of-memory issues in the searches for many users.
You can fix this problem for you with this filter hook. Use this hook to create the WP_Post
objects:
add_filter( 'relevanssi_cached_post_object', function( $post ) { $post->filter = 'raw'; // You probably want to set this flag. return new WP_Post( $post ); } );