I have a post ID stored in a variable from my first query and I'd like to use that to highlight the post with the same ID in my second query, but it's not working.
First loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php foreach(get_field('relationship') as $post_object): ?>
<?php $current = get_the_ID($post_object->ID); ?>
<?php echo $current; ?>
<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>
<?php endforeach; ?>
<?php the_content();?>
<?php endwhile; else: ?>
<?php endif; ?>
The post is queried in my second loop,(not related to the first), only I don't know how to identify it by the variable from the first loop.
Second:
<?php $news_arg=array(
'post_type' => array ('books'),
'post_status' => array( 'publish'),
'posts_per_page' => 20,
);
$arg_query = new WP_Query();
$arg_query->query( $arg );
?>
<?php if( $arg_query->have_posts() ) : ?>
<?php while( $arg_query->have_posts() ) : $arg_query->the_post(); ?>
<?php print_r($arg_query) ?>
<li>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
Thanks.
EDIT: Alex's answer with Chip's correction should work but for some strange reason it doesn't, so I post my full code in case anyone spot the problem. (There are no other queries or any other php on the page):
EDIT: replaced get_the_ID
with get_permalink
and now it works:
<div class="span8 single_c">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post-header">
<h2 class="verseny">
<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a>
</h2>
</div>
<?php foreach(get_field('relation') as $post_object): ?>
<?php $current = get_permalink($post_object->ID); ?>
<?php endforeach; ?>
<div class="well single_p">
<?php echo $current ?>
<?php if(get_field('lead')) {
echo '<p><strong>' . get_field('lead') . '</strong></p>';
} else { } ?>
<?php the_content();?>
<?php endwhile; else: ?>
<?php endif; ?>
</div>
</div>
<div class="span4 single_c">
<div class="well db">
<ul class="nav nav-list">
<?php $arg=array(
'post_type' => array ('books'),
'post_status' => array( 'publish'),
'posts_per_page' => 10
);
$arg_query = new WP_Query();
$arg_query->query( $arg );
?>
<?php if( $arg_query->have_posts() ) : ?>
<?php while( $arg_query->have_posts() ) : $arg_query->the_post(); ?>
>" rel="bookmark" title="">
<?php endwhile; else : ?>
<?php endif; ?>
</ul>
</div>
</div>