Home Forums General Issues Category images


Category images

  • Hey Everyone, let me explain my scenario:
    I have a custom category, wich have for each category a custom field called
    What I’d like to do is show a different size than the original uploaded img, googling and searching I came up with:

    Some values are hardcoded just to make it simple and testable

    // 'custom_catalog_category' is the name of my Custom category, and 39 is id of // the category i have opened in my browser
    $category_image = get_field('immagine_categoria', 'custom_catalog_category_39');
    $size = "page-header";
    $image = wp_get_attachment_image_src( $attachment_id, $size );

    The var_dump returns bool(false).
    I have followed this documentation, but I guess this only works for built-in posts types…

    Anyone has any workaround about this issue?

  • The wp_get_attachment_image() function will work if you actually put your values in the function. Currently, you have $image = wp_get_attachment_image_src( $attachment_id, $size ); but you need to have something like $image = wp_get_attachment_image_src( 39, 'name_of_size' );. Also, your get_field function doesn’t seem correct. I would read more into the documentation about how to use get_field.

  • Hi @ildaniel8

    exactly, your code requires a $attachment_id and $size variable, however your code does not demonstrate that either of these exist.


  • My bad, i copied and pasted the wrong code. ( i said my custom field is “category_image” but really is “immagine_categoria” same thing…)

    $category_image = get_field('immagine_categoria', 'custom_catalog_category_39');
    $size = "page-header";
    $imgURL = wp_get_attachment_image_src( 39,  $size);

    This returns bool(false)

  • Hi @ildaniel8

    Have you debuged $category_image? Also your code doesn’t even make use of it, so the problem is not with ACF, but with either 39, or $size.


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

The topic ‘Category images’ is closed to new replies.