I'm trying to display the post content in a fancybox, and it's almost working good except after clicking on the link it shows only the content of the first post.
So I came across the idea to add the posts ID to the data-src, but for some reason my code is not adding the ID.
<ul>
<?php $args = array('post_type' => 'rm', 'showposts' => 20, 'order' => 'ASC'); $the_query = new WP_Query( $args ); ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $meta = get_post_meta( $post->ID, 'city_council_candidates', true );
$postsData[$row]['links'][$i] = [
'id' => get_the_id(),
];
foreach($postsData as $key => $value) :
$links = $value['links'];
echo '<pre>'; echo var_dump($links); echo '</pre>';
?>
<li class="candidates-wrapper col-12 col-sm-12 col-md-4 col-lg-3 col-xl-2">
<a data-fancybox data-src="#selectableModal-<?php echo $value['id'] ?>" href="javascript:;">
<div class="candidates-img">
<?php the_post_thumbnail(); ?>
</div><!-- .news_img -->
<div class="candidates-name">
<?php echo $meta['name']; ?>
</div>
<div class="candidates-surname">
<?php echo $meta['surname']; ?>
</div>
<div class="candidates-constituency">
<?php echo $meta['constituency']; ?>
</div>
<div style="display: none;max-width:500px;" id="selectableModal-<?php echo $value['id'] ?>">
<h2>
<?php echo $meta['name']; ?><?php echo $meta['surname']; ?>
<h2>
<p>
<?php the_content(); ?>
</p>
</div>
</a>
</li><!-- .news-wrapper -->
<?php
endforeach;
endwhile;
wp_reset_postdata();
?>
</ul>
As you can see I also added the var_dump function to check if the $links
are getting any ID's from the query and the ID's are passed there.
In the console the link looks like this <a data-fancybox="" data-src="#selectableModal-" href="javascript:;">
What did I do wrong?