Home › Forums › Front-end Issues › Problem Using Relationship Field & CPT Query › Reply To: Problem Using Relationship Field & CPT Query
The problem is that you don’t have a main WP loop so get_the_ID() is not returning anything.
I’m only guessing what where this needs to go
<?php
while(have_posts()) : the_post();
?>
<div class="row-fluid dispatch-issue">
<div class="span3″>
<?php the_post_thumbnail(); ?>
<p class="e-dispatch"><a href="<?php echo the_field('external_url'); ?>" target="_blank">View e-Dispatch</a></p>
</div>
<div class="span9″>
<h1><?php the_title(); ?></h1>
<?php
// args
$args = array(
'post_type' => 'article',
'meta_query' => array(
array(
'key' => 'issue',
'value' => '"' . get_the_ID() . '"',
'compare' => '='
)
)
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div>
</div>
<?php
endwhile;
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.