Support

Account

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;
    ?>