Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#25132 closed defect (bug) (invalid)

in_array() within while(have_posts() loop causes the needle to be printed

Reported by: webtechglobal's profile WebTechGlobal Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6
Component: General Keywords:
Focuses: Cc:

Description

This is a strange one.

This behaves normal on lines before my while loop. 18 is in the array and so "no print" is printed. But no extra print happens.

if(in_array(18,$paidid_array)){
             echo 'no print';
}

Different result when used within while have posts. Some values are being printed despite no use of print or echo either. I removed the lines within my if statement to clean things up and found that there is still output "26 24 22 20 18 15" on my plugin game, in the admin. Those are post ID. I replaced the_ID() with $post_ID and populated post_ID using the_ID() but there was no change.

    query_posts( array( 'post_type' => 'downloads') );

    // The Loop
    while ( have_posts() ) : the_post();
    
        if(!in_array(the_ID(),$paidid_array)){
            
        }  
   
    endwhile;
              
    // Reset Query
    wp_reset_query();

Narrowed Down

I printed A before the in_array() and printed B straight after it. The unexpected output is happening between A and B so it is the in_array line for sure.

This is PHP 5.3

Attachments (2)

Wordpress-bug-while-loop-printed-values-array.jpg (15.5 KB) - added by WebTechGlobal 11 years ago.
Printed Numbers
Wordpress-bug-while-loop-printed-values-source-code.jpg (29.7 KB) - added by WebTechGlobal 11 years ago.
Numbers In Source

Download all attachments as: .zip

Change History (4)

#1 @SergeyBiryukov
11 years ago

  • Keywords 2nd-opinion dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Severity changed from major to normal
  • Status changed from new to closed

It's not in_array(), it's the_ID(): tags/3.6/wp-includes/post-template.php#L11.

Use get_the_ID() instead.

#2 @WebTechGlobal
11 years ago

Ah dam I should have known this. Sorry for wasting your time.

Note: See TracTickets for help on using tickets.