How to display gallery by given ID
Question
I’m trying to display post gallery by using given post ID in WordPress.
Using this resource, I reached the following code which suppose to display the post gallery by given ID.
<?php
$id = $_GET['id']; //The ID of the post
$gallery = get_post_gallery( $id, false );
foreach ( $gallery['src'] AS $src ) {
?>
<div class="grid-item">
<img src="<?php echo $src; ?>" alt="gallery image"/>
</div>
<?php
}
?>
But unfortunately I receive the following errors:
Warnning: Trying to access array offset on value of type bool
Invalid argument supplied for foreach()
How can I display the entire post gallery using given ID?
Do note I have gallery in my post.
0
3 months
0 Answers
13 views
0
Leave an answer
You must login or register to add a new answer .