[wp-trac] [WordPress Trac] #14275: excerpt_more filter does not follow $post even after setup_postdata($post)

WordPress Trac wp-trac at lists.automattic.com
Thu Jul 22 13:07:19 UTC 2010


#14275: excerpt_more filter does not follow $post even after setup_postdata($post)
--------------------------+-------------------------------------------------
 Reporter:  jimmynguyc    |        Owner:                 
     Type:  defect (bug)  |       Status:  closed         
 Priority:  normal        |    Milestone:  Awaiting Review
Component:  Query         |      Version:  3.0            
 Severity:  trivial       |   Resolution:  worksforme     
 Keywords:                |  
--------------------------+-------------------------------------------------
Changes (by sirono):

 * cc: sirono (added)
  * component:  Formatting => Query
  * severity:  minor => trivial


Comment:

 add the "global $post;" call directly before your foreach loop:
 this should work :)

 // Default single post with ID 22

 if (have_posts()) : while (have_posts()) : the_post();
     the_content();
 endwhile; endif;


 // Additional custom query
 add_filter('excerpt_more',create_function('',"return $post->ID;"));

 $myposts = get_posts($args);

 global $post;

 foreach ($myposts as $post) : setup_postdata($post);
     echo $post->ID; // gives 519
     the_excerpt();  // shows 22 instead of 519
 endforeach;

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


More information about the wp-trac mailing list