Get the Image
idea for improving - pass an optional string parameter to the get_the_image func (2 posts)

  1. bufny
    Posted 2 years ago #

    1st of all thanks for a great plugin.

    Scenario: I’m using the get_the_image function to customize the post-search.php template. Let’s say I have a post with two pictures sunset.jpg an sunrise.jpg, sunset.jpg being the 1st one in the post. If a user is searching for sunrise the post will appear in search result but the display thumbnail will be sunset.jpg (being the 1st image in the post). It will be useful to optionally pass the search string to the get_the_image function and the function should try to match the search string using regular expressions to some image properties (title, alt, filename).

    Another scenario, a post contains some pictures of people, I’m searching for some one, in the search result I will get the 1st picture that might be of somebody else.


  2. bufny
    Posted 2 years ago #

    my own solution:

    in the get_the_image_by_scan function, just after preg_match_all call:

    $search_query =  get_search_query();
    if (isset($matches) && !empty($search_query)) {
        $full_image_tags = $matches[0];
        $src_image_tags = $matches[1];
        foreach ($full_image_tags as $index => $full_image_tag) {
            if (stripos($full_image_tag, $search_query) !== FALSE) { // just return 1st match to the search_query
                return array('src' => $src_image_tags[$index]);

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Get the Image
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.