[wp-trac] [WordPress Trac] #25132: in_array() within while(have_posts() loop causes the needle to be printed

WordPress Trac noreply at wordpress.org
Sat Aug 24 01:28:51 UTC 2013


#25132: in_array() within while(have_posts() loop causes the needle to be printed
---------------------------+--------------------------------------
 Reporter:  WebTechGlobal  |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  General        |    Version:  3.6
 Severity:  major          |   Keywords:  2nd-opinion dev-feedback
---------------------------+--------------------------------------
 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

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25132>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list