I have 2 Slick Sliders that have their own loops only being filtered by each post types tag, which are working perfectly. However, I'm trying to pass certain custom fields outside of each loop into a modal. Here's the code for one of the sliders, which is basically the same for the second one:
Loop:
<section class="regular slider-actual actual-projects-container">
<?php $args = array('post_type' => 'proyecto', 'tag' => 'actual'); ?>
<?php $loop = new WP_Query($args); ?>
<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); $postid=the_ID();?>
<a href="#" data-toggle="modal" data-target="#myModal-<? the_ID();?>">
<img src="<?php the_field('project_image'); ?>">
</a>
<div class="projects-container">
<div class="name-bar row">
<div class="col-7">
<h2 class="proj-title"><?php the_field('project_name'); ?></h2>
</div>
<div class="col-5">
<h2 class="proj-cat"></h2>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<h1>No posts here!</h1>
<?php endif; ?>
</section>
Modal:
<div class="modal fade" id="myModal-<? the_ID(); ?>" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'proyecto', true);
?>
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><?php the_field('project_name'); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="modBody">
<?php the_field('project_video');?>
</div>
</div>
</div>
</div>
I've been reading and it seems like the post ID isn't getting passed into the modal considering the modal is displaying only the first posts info regardless of which slide is being click on. So at least it's retrieving a post, but not the post it corresponds to. If it helps any I'm using ACF for the custom fields. Any help would be appreciated, thanks.
You could use echo get_field( 'meta_key', get_the_ID() );
or possibly change $postid
to get_the_ID()
or do something like global $post;
and echo $post->ID;