0

I'm trying to get an image for I previously assigned to a category using ACF.

here's what I'm doing:

$category_image = the_field('cat_small', $linkedcat);

where $linkedcat is something like category_280

When I echo $category_image, i see an array, like so:

261, , catsmall, , , http://localhost/current/dpf/wp-content/uploads/2012/12/catsmall.jpg, Array

Any idea what I'm doing wrong? Many thx!

Alex

2 Answers 2

1

Whenever in doubt, consult the documentation and nice plugins like ACF are very well documented.

It depends on how you set the image field, but from this page Field Types -> Image, looks like you set you field to return an object.

Instead of using the_field, which prints the value, you need get_field:

$category_image = get_field('cat_small', $linkedcat);

And then:

$image = $category_image['url'];

Or, if available:

$thumb = $category_image['sizes']['thumbnail'];

Also, instead of echo, use var_dump to debug arrays.

0

If you want to assign image on your category or taxonomy, I suggest Categories Image Plugin, it will allow you to add image with category or taxonomy.

Use <?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?> to get the url and put it in any img tag in (category or taxonomy) template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.