WordPress.org

Ready to get started?Download WordPress

Forums

Exclude image titles from search results (8 posts)

  1. donnytree
    Member
    Posted 1 year ago #

    I would like to exclude image titles from search results. For instance, if I have an image called image-wikipedia.jpg, right now, if I search for Wikipedia the story that uses that image is returned in the results.

    I tried the Simply Exclude plugin and Relevanssi plugin, but neither worked. I don't know if it's because I am using a custom search results page that these plugins aren't working.

    Any help would be much appreciated. Thanks!

  2. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    I would like to exclude image titles from search results

    Why? Don't like traffic and ranking from image links? Or, do you want to hide the identity of images?

  3. donnytree
    Member
    Posted 1 year ago #

    Because the image title does not necessarily have anything to do with the search. For instance, in my above example, I may label an image I got from Wikipedia with the source name, but that doesn't mean I want it in search results if someone is looking for an article about Wikipedia. It is for an article-based research website so it is the nature of the information I am trying to deliver.

  4. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    It is for an article-based research website so it is the nature of the information I am trying to deliver.

    Good enough! Then will it not be a nice thing to name the image relevant to your research topic and get the benefit of image search also coming to your site? Well, if you don't want that just give it some random numbers and characters as the image name.

    Now about images from Wikipedia: unless you use the links generated by Wikipedia and use the licenses under which you use them, you do not need to use the name Wikipedia. If you use images other than PD images/ CC0 images, still you will be violating the terms by not displaying the source licensing that including the name of Wikipedia. The better option will be to look for PD images or CC0 images from Wikipedia that you can use in whatever way you like, but you cannot claim authorship or copyright.

  5. donnytree
    Member
    Posted 1 year ago #

    Thanks for the input Krishna.

    However I would still like to figure out a way to do this if anyone has any advice. Thanks!

  6. cornhustlah
    Member
    Posted 1 year ago #

    I ran into this problem today..

    I am not using an attachment template and search results are coming up with attachment posts due to matching results in the attachment titles, so I get results that pointlessly takes the user to a page with nothing but the attachment image and the header and footer. To work around this issue, i simply added a line to my loop in search.php:

    <?php while ( have_posts() ) : the_post();
    if (get_post_type($post->ID) == 'attachment' || $post->post_status == 'private'){continue;}?>
    ...
    
    <?php endwhile; ?>

    I also noticed that private pages were also getting returned, so that's what that post_status condition in my if statement is all about.

  7. donnytree
    Member
    Posted 1 year ago #

    Thanks cornhustlah! Very simple solution, but I am afraid I can't get it to work for me. I am using the following code:

    query_posts($query_string . '&post_type=post&posts_per_page=-1');
    $results_count = $wp_query->post_count;

    So the count would be off I think if I used your method. I also tried to enter your above code in my while loop, but it didn't work?

    Thanks!
    Donna

  8. cornhustlah
    Member
    Posted 1 year ago #

    yea, your count would get messed up, but i think you could keep it in check with every skipped attachment like so:

    if (get_post_type($post->ID) == 'attachment'){
      $results_count--; continue;
    }

    as for it working in general with your loop, i couldnt be sure what might be causing it fail unless i had a look at all of your code.. can you post your full loop here for me to view?

Topic Closed

This topic has been closed to new replies.

About this Topic