I am using the Taxonomy Meta plugin and have followed all instrauctions but feel like something is wrong with what I am doing. I just want to pull the image that is assigned to each category is a custom taxonomy and display it on a page template..
the github repo of the plugin can be found here: https://github.com/rilwis/taxonomy-meta
please help, I get everything to show but the image and when I look in the source the image path isnt there just an empty img tag.
I can get an image to print using this:
$meta = get_option('additional');
if (empty($meta)) $meta = array();
if (!is_array($meta)) $meta = (array) $meta;
$meta = isset($meta['5']) ? $meta['5'] : array();
$images = $meta['community-image'];
echo '<ul>';
foreach ($images as $categories) {
// get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
$src = wp_get_attachment_image_src($categories, 'thumbnail');
$src = $src[0];
$args=array(
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'properties_community'
);
$categories=get_categories($args);
// show image
foreach($categories as $category) {
echo '<li><a href="' . home_url() . '/?property_communities='. $category->slug .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '><img src="'.$src.'"/>' . $category->name.'</a> </li> ';
}
}
echo '</ul>';
but I cannot figure out how to make it where the image matches the category being displayed.. I just put the number 5 in there to see if it worked which it does but if I try using $category->term_id it doesnt work and I am a bit lost from here..
UPDATE:
I am now able to pull the images assigned to each category and print the names but I am getting this error “Warning: Invalid argument supplied for foreach() in /home/../themes/../my-template.php on line 39”
Here is my code
$args = array( 'taxonomy' => 'properties_community' );
$terms = get_terms('properties_community', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '<p class="my_term-archive">';
foreach ($terms as $term) {
$meta = get_option('additional');
if (empty($meta)) $meta = array();
if (!is_array($meta)) $meta = (array) $meta;
$meta = isset($meta[$term->term_id]) ? $meta[$term->term_id] : array();
$images = $meta['community-image'];
foreach ($images as $att) {
// get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
$src = wp_get_attachment_image_src($att, 'medium');
$src = $src[0];
// show image
echo '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '"><img src="'.$src.'" />' . $term->name . '</a>';
}}
}
Anyone see why I may be getting this error? I dont see anything wrong with the foreach :/
Line 39 would be this: foreach ($images as $att) {
Got it