Not Able to Get Custom Post Type Gallery Images URL

Question

I have a CPT called books and I am able to loop through it like

<?php
$loop = new WP_Query(array(
    'post_type' => 'books',
    'tax_query' => array(
        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => 'romance'
        )
    )
)
);
while ($loop->have_posts()):
    $loop->the_post();

endwhile;
wp_reset_query();

?>

Now I want to display the Post Galley images with my own class so I tries to use this code

   if ( $gallery = get_post_gallery( get_the_ID(), false )){
       foreach ( $gallery['src'] AS $src ) {
           ?> 
            <img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
            <?php
        }
   }

from Here at codex

like

<?php
$loop = new WP_Query(array(
    'post_type' => 'photo',
    'tax_query' => array(
        array(
            'taxonomy' => 'phototypes',
            'field' => 'slug',
            'terms' => 'public'
        )
    )
)
);
while ($loop->have_posts()):
    $loop->the_post();
    if ($gallery = get_post_gallery(get_the_ID() , false))
    {
        foreach ($gallery['src'] AS $src)
        {
?> 
                    <img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
            <?php
        }
    }
endwhile;
wp_reset_query();
?>

But this is not returning anything , not even empty image tags and no error. Can you please let me know what I am missing here?

0
, , Behseini 1 year 0 Answers 89 views 0

Leave an answer