0

I have this section in my website where i use wp_get_attachment_image_src() to get all the images associated with the post, but now you want to get a certain size (size: listing_grid):

 <?php  $args = array(
            'post_parent'    => $post->ID,
            'post_type'      => 'attachment',
            'numberposts'    => 15, // -1, show all
            'post_status'    => 'any',
            'post_mime_type' => 'image',
            'orderby'        => 'menu_order',
            'order'           => 'ASC'
       );

$images = get_posts($args);
if($images) { ?>


<images>
    <?php foreach($images as $image) { ?>
    <image><![CDATA[<?php echo wp_get_attachment_url($image->ID); ?>]]></image>
    <?php } ?>
</images>   
<?php } ?>
3
  • use get_the_post_thumbnail_url( $image->ID, 'full' ), instead of wp_get_attachment_url( $image->ID ); and see if this works
    – maverick
    Aug 18, 2018 at 15:43
  • this might help you wordpress.stackexchange.com/questions/45033/…
    – maverick
    Aug 18, 2018 at 15:55
  • the first solution does not work, but I'll see if I get something in the second option. Thank you.
    – E. Mendes
    Aug 19, 2018 at 15:16

1 Answer 1

0

Thanks maverick, your solution works

<?php  $args = array(
            'post_parent'    => $post->ID,
            'post_type'      => 'attachment',
            'numberposts'    => 15, // -1, show all
            'post_status'    => 'any',
            'post_mime_type' => 'image',
            'orderby'        => 'menu_order',
            'order'           => 'ASC'
       );

$images = get_posts($args);
if($images) { ?>


<images>
    <?php foreach($images as $image) { ?>
    <image><![CDATA[<?php echo wp_get_attachment_image_src( $image->ID, 'listing_gallery_2x')[0]; ?>]]></image>
    <?php } ?>
</images>   
<?php } ?>

Your Answer

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

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