Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Add filter to post thumbnail ID #829

Closed
wants to merge 1 commit into from
Closed

Add filter to post thumbnail ID #829

wants to merge 1 commit into from

Conversation

claytoncollie
Copy link

I created an issue for this a while back before knowing how to create a PR. But now with my new super powers, I was able to make this addition. :)

My use case was that I had a list of people in the search results and I needed a way to have a fallback image for when the person did not have a featured image. The results display the featured image and not having an image threw off my styling.

Here is the callback I am using with this filter.

/**
 * When a featured image is not present, use another attachment ID provided by database option.
 *
 * @param int $post_thumbnail_id Post thumbnail ID.
 * @param int $post_id Post ID.
 *
 * @return int
 */
function prefix_get_post_thumbnail_id( $post_thumbnail_id, $post_id ) {

	if ( ! in_array( get_post_type( $post_id ), array( 'your_post_type' ), true ) ) {
		return $post_thumbnail_id;
	}

	if ( ! has_post_thumbnail( $post_id ) ) {
		$post_thumbnail_id = intval( 'your_fallback_image_id' );
	} else {
		$post_thumbnail_id = get_post_thumbnail_id( $post_id );
	}
		
	return $post_thumbnail_id;

}```

@rayrutjes
Copy link
Member

Thanks a lot for your active participation in this plugin. We wanted to let you know that we chose to go in another direction regarding the way we integrate Algolia to WordPress. More information can be found here.

@rayrutjes rayrutjes closed this May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants