• Hello Ernest,

    This plugin is great – the image field I’m looking to use is a custom field, and it’s awesome that you have a selector to choose which size image to use, but from what I’m seeing the custom field image is not being sent the image size selection.

    Tested this with a brand new image upload which I know has the “miniLogo” size in our functions.php file.

    Is something you can verify/patch?

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    Well, I am not sure if that is doable with custom field attachments, but we can try something.

    add_filter('asp_results', 'asp_get_attachments_size', 10, 1);
    function asp_get_attachments_size($results) {
    	$field = 'my_custom_field';
    	$size = 'thumbnail';
    
    	foreach ( $results as $k => &$r ) {
    		$val = get_post_meta( $r->id, $field, true );
    		if ( $val != null && $val != "" ) {
    			if ( is_numeric($val) ) {
    				$imx = wp_get_attachment_image_src(
    					$val, $size, false
    				);
    				if ( !is_wp_error($imx) && $imx !== false && isset($imx[0]) )
    					$r->image = $imx[0];
    			} else if ( $val != "" ) {
    				$r->image = $val;
    			}
    		}
    	}
    	return results;
    }

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    If this does work, then I can try implementing a permanent solution for the upcoming release.

    Best,
    Ernest M.

    Thread Starter megabase

    (@megabase)

    Ah, thought it was working but still seems weird I think.

    • This reply was modified 3 years, 4 months ago by megabase.
    Plugin Author wpdreams

    (@wpdreams)

    The size might be named differently. I am guessing the “thumbnail” as the default, but it is very much possible it is different from that. Try checking the registered image sizes list, you can see it here: https://i.imgur.com/b0WdNIs.png
    Then change the $size variable accordingly. Also, don’t forget to change the $field variable as well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Field does not respect Image Size Selection’ is closed to new replies.