Home Forums General Issues Relationship field does not allow for post ID to be reset, help. Reply To: Relationship field does not allow for post ID to be reset, help.

  • Actually that did not solve the problem. It seems anytime i put a relationship field in the header, page, sidebar, anywhere – anytime there is a wordpress default loop after that, that loop won’t run.

    If i comment out this code in my header-news.php file, then the rest of the page will run just fine.

    I have tried variations of this code too, but it doesnt seem to work.

    Maybe if you can take a look you can spot something wrong with it.

    $post_id = 19;
    $headerqry = array( 
    	'p' => $post_id,
    	'post_type' => 'any',
    	'posts_per_page' => 1,
    	'status' => 'published'
    $loop = new WP_Query( $headerqry );
    if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
    $posts = get_field('header_promo_banner');
    if( $posts ): ?>
        <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
    					$attachment_id = get_field('promo_image');
    					$size = "promo-header";
    					$image_attributes = wp_get_attachment_image_src( $attachment_id, $size );
    				if( $image_attributes ) {
            	<a href="<?php echo the_field('promo_url'); ?>" target="_blank"><img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>"></a>
        <?php } endforeach; ?>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>
    <?php endwhile; endif; wp_reset_query(); ?>

    On most pages i am using global $post; $post_id = $post->ID; to get the ID of the current page outside of the loop.

    I was hoping that wp_reset_query would reset the loop and let the items after this query run, but it doesnt seem to work.

    Then the code in my single-10.php file is pretty basic:

    while ( have_posts() ) : the_post(); ?>
    	<div class="main-photo-wrapper">
      	<img src="<?php echo the_field('header_photo'); ?>" style="width:100%; height:auto;" alt="<?php echo the_field('header_alt_text'); ?>"/>
      <div class="title-bar">
      	<h2><?php the_title(); ?></h2>
      <div class="article-content">
      <?php the_content(); ?>
    <?php endwhile;  // end of the loop. ?>