[wp-trac] [WordPress Trac] #12212: post__in can't manage empty array properly

WordPress Trac wp-trac at lists.automattic.com
Sun Feb 14 02:32:38 UTC 2010


#12212: post__in can't manage empty array properly
--------------------------+-------------------------------------------------
 Reporter:  lifeless85    |       Owner:  ryan          
     Type:  defect (bug)  |      Status:  new           
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:  2.9.1         
 Severity:  normal        |    Keywords:  post__in      
--------------------------+-------------------------------------------------

Comment(by lifeless85):

 no no no ... you didn't get the point...
 assume you have this behaviour:

 {{{
 $sticky=get_option('sticky_posts');
 $args=array(
         'showposts'=>2,
         'post__in' => $sticky,
         'caller_get_posts' => 1,
         'orderby'=>'meta_value',
         'meta_key'=>'from',
         'order'=>'ASC'
 );
 include('so-sidebar.php');
 $args=array(
         'showposts'=>2,
         'post__not_in' => $sticky,
         'caller_get_posts' => 1,
         'orderby'=>'meta_value',
         'meta_key'=>'from',
         'order'=>'ASC'
 );
 include('so-sidebar.php');
 }}}
 and inside so-sidebar.php you have a custom loop like this:
 {{{
 <?
 $so_query = new WP_Query($args);
 if ($so_query->have_posts()) :
         while ($so_query->have_posts()) :
                 $so_query->the_post();
 ?>
 <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
         <h2><a href="<?php the_permalink() ?>"><?php the_title();
 ?></a></h2>
         <div class="entry"><?php the_excerpt();?></div>
 </div>
 <?php
         endwhile;
 endif;
 ?>
 }}}

 OK, now i guess you'll be asking yourself:

 why all of this !?!?

 The answer is clear.
 Because if you use {{{'orderby'=>'meta_value'}}} to sort your post, you
 can't have all stiky posts at the top (and sorted too).
 So ... this is the frustrating way, i do this.

 Now, this is bad, because yes i could do this in my theme:

 {{{
 $sticky=get_option('sticky_posts');
 if( empty($stiky) ) {
         //do all the math here
 }
 }}}

 But, this is like saing SELECT ALL ITEMS FROM AN EMPTY GROUP the result
 should be another EMPTY GROUP and now this is not true, this is like
 swearing against the LOGIC and MATH god who rule us all. you are telling
 me the same thing chrisscott told me before, this is an hard work, it
 would be easier to fix it your theme ... not exactly the kind of thing i
 thought i would have found here...

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12212#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list