Support

Account

Home Forums General Issues Filtering image size when getting image from taxonomy term

Helping

Filtering image size when getting image from taxonomy term

  • Hello

    I have a custom type with categories, where I have a custom field to add an image, see:

    screenshot 1

    Screenshot 2

    I display this image in archive.php using this code:

    $product_category_img = get_field('product_category_image', 'product_categories_' . $term->term_id );

    <img src="<?php echo $product_category_img; ?>" alt="<?php echo $term->name; ?>">

    I would like to filter the image size to use a custom size, to achieve this I’ve tried:

    $product_category_img = get_field('product_category_image', 'product_categories_' . $term->term_id );
    $size = "product-thumb";
    $image = wp_get_attachment_image_src( $product_category_img, $size );	

    <img src="<?php echo $image; ?>" alt="<?php echo $term->name; ?>">

    However, this does not output the image.

    Any for how to use a custom image size in this situation?

    Many thanks
    Dave

  • Hi @juxprose

    To obtain a custom image size, you must select the ‘Image ID’ return value setting. You need the ID to load a custom size via the wp_get_attachment_image_src function.

    You can also use the ‘Image Object’ return type to get an array containing all the image data including all the ‘sizes’.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Filtering image size when getting image from taxonomy term’ is closed to new replies.