algoliasearch-wordpress
algoliasearch-wordpress copied to clipboard
Add filter for $post_thumbnail_id to replace with default image
What did you expect to happen?
My post type, People, is heavily driven by the featured image. When indexing post objects without a featured image, my front end view is thrown off. There is a row of 4-5 objects and 1 doesn't have an image. Looks bad. I created a Customizer option that holds the default headshot image ID that I would like to use when a featured image is not present.
Under Aglolia Utils, line 94 could have a filter that defaults to the thumbnail ID but allow me to pass another ID for Algolia to index.
$post_thumbnail_id = apply_filters( 'algolia_post_thumbnail_id', get_post_thumbnail_id( (int) $post_id ), $post_id );
Then my filter would look like this.
/**
* When a featured image is not present, use another attachment ID provided by database option
*
* @param int $id Post thumbnail ID.
* @param int $post_id Post ID.
*
* @return int
*/
function prefix_fallback_for_post_thumbnail_id( $id, $post_id ) {
if ( ! has_post_thumbnail( $post_id ) ) {
$id = intval( get_option( 'default-headshot' ) );
} else {
$id = get_post_thumbnail_id( (int) $post_id );
}
return $id;
}`
Is it possible to add this filter?
Hello! any updates on this? I am also interested in applying default thumbnail images if posts don't have a real one.