Support » Fixing WordPress » Search on our website shows wrong image

  • Try searching for ‘staff’ on our site. The search results show one result “Ministers and Staff”, with a photo and a description of our minister. However, the photo is not one of our minister; it is another photo on the same page. If you click on the ‘Continue Reading’ link to go to that page, you will see the correct image.

    I have tried clearing the site’s caching plugin’s cache, cleared the browser cache, and even replaced the built-in search with the Relevanssi plugin, all with no change.

    That page does not have a featured image.

    Any ideas what could be wrong?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    Have you tried:
    – deactivating ALL (yes all) plugins temporarily to see if this resolves the problem (plugin functions can interfere). If this works, re-activate them individually (one-by-one) to find the problematic plugin(s).
    – switching to the unedited default Theme (Twenty Seventeen.) for a moment using the WP dashboard to rule out any theme-specific issue (theme functions can interfere like plugins).

    the image shown in the search result is the ‘featured image’ as it is set for this page;

    consider to change the ‘featured image’ to be the correct image of the minister.

    if you suspect this to be an issue with your theme, please ask in https://wordpress.org/support/theme/nirvana

    Thanks for your quick responses.

    1) Disabling all plugins and changing the theme is not a practical thing to do on a website that is live.

    2) As I said in my post, the page does NOT have a featured image (none of our pages do, as having a featured image does not seem useful in our non-blog website — we don’t use posts). However, I made the needed photo be the featured image for the page and that did indeed fix the problem.
    Is there any way of saying ‘use the first image in the page if there is no featured image’? I’m assuming that the search produces an ‘excerpt’ of the page (even though, by default, only posts have excerpts). What I really need is a true extract of the first part of the page, including any image there.

    Is there any way of saying ‘use the first image in the page if there is no featured image’? I’m assuming that the search produces an ‘excerpt’ of the page (even though, by default, only posts have excerpts). What I really need is a true extract of the first part of the page, including any image there.

    you might need to edit /content/content.php of your theme (in a child theme) to achieve this.
    for details, please ask in your theme’s support section at https://wordpress.org/support/theme/nirvana

    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.

    • This reply was modified 2 years, 3 months ago by Tony Sanjaya.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search on our website shows wrong image’ is closed to new replies.