#14275 closed defect (bug) (worksforme)
excerpt_more filter does not follow $post even after setup_postdata($post)
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Query | Version: | 3.0 |
| Severity: | trivial | Keywords: | |
| Cc: | sirono |
Description
A simple test by returning the $post-ID in the filter function and this is what I get :
// 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);
foreach ($myposts as $post) : setup_postdata($post);
echo $post->ID; // gives 519
the_excerpt(); // shows 22 instead of 519
endforeach;
Change History (3)
- Resolution set to worksforme
- Severity changed from normal to minor
- Status changed from new to closed
- Cc sirono added
- Component changed from Formatting to Query
- Severity changed from minor to trivial
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;
Note: See
TracTickets for help on using
tickets.

This is because setup-postdata() doesn't set the global $post variable. this is done in WP_Query().the_post();