Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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