Skip to content

Commit

Permalink
Fixes incorrect thumbnail image displayed for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaydsouza committed Dec 30, 2019
1 parent 2da0e70 commit 7fe7eed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions includes/main-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function get_crp( $args = array() ) {
* @since 1.9
*
* @param array $args Arguments array.
* @return object $results
* @return object $results Array of related post objects
*/
function get_crp_posts_id( $args = array() ) {
global $wpdb, $post, $crp_settings;
Expand Down Expand Up @@ -452,7 +452,7 @@ function get_crp_posts_id( $args = array() ) {
$where = $match;
$where .= $now_clause;
$where .= $from_clause;
$where .= " AND $wpdb->posts.post_status = 'publish' "; // Only show published posts.
$where .= " AND $wpdb->posts.post_status IN ('publish','inherit') "; // Only show published posts or attachments.
$where .= $wpdb->prepare( " AND {$wpdb->posts}.ID != %d ", $source_post->ID ); // Don't include the current ID.

if ( isset( $args['same_author'] ) && $args['same_author'] ) {
Expand Down
4 changes: 3 additions & 1 deletion includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ function crp_get_the_post_thumbnail( $args = array() ) {
// If there is no thumbnail found, check the post thumbnail.
if ( ! $postimage ) {
if ( false !== get_post_thumbnail_id( $result->ID ) ) {
$postthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ), array( $args['thumb_width'], $args['thumb_height'] ) );
$attachment_id = ( 'attachment' === $result->post_type ) ? $result->ID : get_post_thumbnail_id( $result->ID );

$postthumb = wp_get_attachment_image_src( $attachment_id, array( $args['thumb_width'], $args['thumb_height'] ) );
$postimage = $postthumb[0];
}
$pick = 'featured';
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ You can insert the related posts anywhere in your post using the `[crp]` shortco
* Selecting date order now orders the related posts by newest first
* Fixed PHP warning in the widget
* Stop using `current_time( 'timestamp' )`
* Fixes incorrect thumbnail image displayed for attachments in the related posts list

= Earlier versions =

Expand Down

0 comments on commit 7fe7eed

Please sign in to comment.