Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Search on our website shows wrong image

Discussion in 'Misc WordPress Requests' started by Tony Sanjaya, Oct 28, 2017.

  1. Tony Sanjaya

    Guest

    Reply To: Search on our website shows wrong image, by Tony Sanjaya

    is it fixed?
    if no, here is how to do it.


    if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else {
    // No post thumbnail, try attachments instead.
    $images = get_posts(
    array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID,
    'posts_per_page' => 1, /* Save memory, only need one */
    )
    );

    if ( $images ) {
    echo '<img src="' . wp_get_attachment_image_src( $images[0]->ID, 'post-thumbnail' ) . '" alt="" />';
    }
    }


    Put this code inside the loop.
    So it checks if there is no featured image, then it will search the first image.

    Reply To: Search on our website shows wrong image
     
    #1

Share This Page

Web Hosting