0

Is there a way to fetch the ALT/TITLE of ALL images in the media gallery?

I think this would be an easy way for a website to have a Pictures page that just pulls all of the images from the media gallery, granted it would only be necessary in certain scenarios.

I don't need instructions on how to create a Pictures page, just how to pull all of the image URLs. Thanks!

0
<?php

/*
* Template Name: Gallery Page
*/

$query_images_args = array(
    'post_type'      => 'attachment',
    'post_mime_type' => 'image',
    'post_status'    => 'inherit',
    'posts_per_page' => - 1,
);

$query_images = new WP_Query( $query_images_args );

?>
<?php get_header();?>
<div class="main">
    <div class="row">
        <?php foreach ( $query_images->posts as $image ) {?>
            <div class="col-md-3">
                <?php echo wp_get_attachment_image( $image->ID,'thumbnail' );?>
            </div>
        <?php }?>

    </div>
</div>
<?php get_footer();?>
2
  • it's work thank you... can you answer my other question?
    – SauRav
    Aug 8 at 3:48
  • please.... can you answer question this link
    – SauRav
    Aug 8 at 3:56
0
$query_images_args = array(
    'post_type'      => 'attachment',
    'post_mime_type' => 'image',
    'post_status'    => 'inherit',
    'posts_per_page' => - 1,
);

$query_images = new WP_Query( $query_images_args );

$images = array();
foreach ( $query_images->posts as $image ) {
    $images[] = wp_get_attachment_image( $image->ID,'thumbnail' );
}
3
  • how to use this code? can you please tell me
    – SauRav
    Aug 8 at 3:17
  • Create a page with your custom template and put this code in your template file
    – Nayan
    Aug 8 at 3:36
  • Please check new posted code
    – Nayan
    Aug 8 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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