#25132 closed defect (bug) (invalid)
in_array() within while(have_posts() loop causes the needle to be printed
Reported by: | 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)
Change History (4)
Note: See
TracTickets for help on using
tickets.
It's not
in_array()
, it'sthe_ID()
: tags/3.6/wp-includes/post-template.php#L11.Use
get_the_ID()
instead.