wp_get_attachment_url() working but wp_get_attachment_image() not working
-
Hi folks,
I am trying to make a widget which takes post id as input from user and displays images of the specified post in sidebar. wp_get_attachment_url()gets me the url but in the next line wp_get_attachment_image()doesn’t work on same photo=>id. I don’t know where I am going wrong.
Sharing the code of the widget I am tried to put together after going through other wordpress support group posts:
function widget( $args, $instance ) { echo $args['before_widget']; $photos = get_children( array('post_parent' => $instance['post'], 'post_type' => 'attachment', 'post_mime_type' => 'image') ); //for getting inline post images only $post_id=$instance['post']; $content_post = get_post($post_id); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); if (!empty($photos)) : //Loop through each attachment.. foreach ($photos as $photo_id => $photo) : //getting inline post images only $url = wp_get_attachment_url($photo_id); $position = strpos($content, $url); if($position){ echo $post_id; //working echo wp_get_attachment_url($photo_id); //not working wp_get_attachment_image($photo_id, 'thumbnail') ; } endforeach ; endif ;
- The topic ‘wp_get_attachment_url() working but wp_get_attachment_image() not working’ is closed to new replies.