WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i can't manage to "see" the value of $originalArticle in echo '/'.$originalArticle.'== &'.$sameArticle; : i tried with "global" before, but it does not work... The output is for example :

/== &48

Any help?

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <?php $originalArticle = the_ID(); //this works ?>
        <h2 class="entry-title">…</h2>
        <div class="entry-utility">…</div><!-- .entry-utility -->
                $cats = get_the_category();
                $cat_obj = array_shift($cats);
                $cat_id = (int) $cat_obj->cat_ID;

                $second_query = new WP_Query( 'cat='.$cat_id.'&posts_per_page=2' );
                while ( $second_query->have_posts() ) : $second_query->the_post();

                    $sameArticle = get_the_ID();

                    /* HERE */ echo '/'.$originalArticle.'== &'.$sameArticle; //output : /== &48

                    if ( $originalArticle == $sameArticle )
                    } else {

Thanks for your help

share|improve this question
up vote 2 down vote accepted

Use get_the_ID(), not the_ID(). The latter just prints the value, it does not return a value you can store in a variable.

So …

$originalArticle = get_the_ID();
share|improve this answer
Thanks a lot toscho! – Paul May 22 '12 at 9:00
<?php $originalArticle = the_ID(); //this works ?>

this should be changed to

<?php $originalArticle = get_the_ID(); //this works ?>
share|improve this answer
Oops... Toscho has already answered above.. !! – Subharanjan May 22 '12 at 6:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.