Support » Plugins and Hacks » [Resolved] Filter by featured image size

[Resolved] Filter by featured image size

  • Hi,

    this plugin may come in handy. Due to a theme change on my site some old posts have to small original sizes, now. It would be nice to be able to display all posts with an original image smaller than a size given as width and height in pixel (e.g. 400×600).

    I think function wp_get_attachment_image_src() may be used for this:

    $arrImage = wp_get_attachment_image_src( $attachment_id, array($min_width, $min_height));
    if (empty($arrImage))  { return ''; }
    $url     = $arrImage[0];
    $width   = $arrImage[1];
    $height  = $arrImage[2];
    $resized = $arrImage[3];
    return (!$resized && ($width < $min_width || $height < $min_height)) ? $url : '';


Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Martin Stehle


    I think this is a theme-specific function and better stored in the theme’s function.php.

    I think it is easier

    1. to register a new post thumbnail size in the function.php via add_image_size()
    2. to regenerate the thumbnail images with the fine plugin “Regenerate thumbnails”
    3. to change the call of the_post_thumbnail( $new_size_name ) with $new_size_name as the name of the new size you set in step 1

    1. Set the thumbnail size in Settings > Media
    2. and then use “Regenerate Thumbnails” once

    Hi Hinjiriyo,

    Sorry but this does not solve my problem. There are over 2000 images on the site and several of the old original images have a size below half of the size of the new image size. Resizing these images will result in quite bad quality.

    The problem is to identify these images and replace them with a new increased original or delete them. And I think your plugin could be a great help to do this.

    Plugin Author Martin Stehle


    Ok, this could be a new filter, lets call it “Size Filter”.

    I will implement it and will inform you here.

    Plugin Author Martin Stehle


    Hello Jochen, your requested feature is now implemented in the new version 2.0.

    I hope you’ll find it useful.

    Thank you very much for that cool filter!

    Unfortunately a typo has found it’s way into a SQL statement and the number of matched posts is always zero.

    In function get_post_ids_of_featured_image_ids() you have some SQL which begins with "SELECT post_id FROM wp_postmeta WHERE ...". I think the database name ‘wp_postmeta’ should have been $wpdb->postmeta as in the other SQL statements.

    After repairing that statement I could see from my debug output that 634 posts with a featured image exists and 282 have to small featured images. The number of affected posts is 300 at the end of function get_post_ids_of_to_small_thumbnails(). It’s ok that this number is higher than 282 as one featured image may be assigned to several posts.

    But the number of displayed post links in the admin page is only 233. As I have not any other constraints, I think it should be 300, too. Are there any limitations to the output?

    Plugin Author Martin Stehle


    Jochen, thank you very much for your detailed feedback. I have revised the SQL statement in the current plugin version 2.0.2.

    I suppose the reason for the lower number of post is the default constraint of the query only to posts without including pages and other post types.

    What happened if you would add the post type filter (“Beitragstypfilter”) and include the other post types?

    Hi Hinjiriyo, the update solved the problem.

    And your assumption that the exclusion of other post types are the reason for only 233 links displayed on the admin page was right. With all post types selected I get the proper result of 300 links.

    Thank you for the good work.

    Plugin Author Martin Stehle


    Thank you for your reply.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Filter by featured image size’ is closed to new replies.