Reputation: 51
i'm trying to pull the alt text from an image array to use elsewhere but i'm getting nowhere..
here's the code:
global $post;
$args = array( 'numberposts' => 12, 'post_type' => 'clientes', 'orderby' => 'ASC');
$myposts = get_posts( $args );
$alt_text = get_post_meta($args , '_wp_attachment_image_alt', true);
foreach( $myposts as $post ) : setup_postdata($post);
?>
<li>
<!--BEGIN .hentry -->
<div class="post_box">
<div class="post-thumb left gallery">
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail('full'); ?>
<div class="overlay"><img src="<?php echo $alt_text; ?>.jpg" /></div>
</a>
</div>
<!--END .hentry-->
</div>
I'm pretty certain that my fault is with this line:
$alt_text = get_post_meta($args , '_wp_attachment_image_alt', true);
but I lack the knowledge to fix it...
thanks
b
Upvotes: 0
Views: 649
Reputation: 6346
You are misusing get_post_meta
: the first argument should be the post identifier not an array of args.
you need to call get_post_meta
inside the foreach
loop to pull each post's unique data:
foreach( $myposts as $post ) :
$alt_text = get_post_meta($post->ID , '_wp_attachment_image_alt', true);
endforeach;
Upvotes: 1