Home › Forums › General Issues › Category images
Hey Everyone, let me explain my scenario:
I have a custom category, wich have for each category a custom field called
“category_image”
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 );
var_dump($image);
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.
Thanks
E
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);
var_dump($imgURL);
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.
Thanks
E
The topic ‘Category images’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.