Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 -->
                <?php 
                $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
add comment

2 Answers

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
add comment
<?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
add comment

Your Answer

 
discard

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.