#21485 closed enhancement (wontfix)
Exclude current post from Recent Posts widget
| Reported by: | Asif2BD | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Widgets | Version: | 2.8 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Checking demo site - http://twentytwelvedemo.wordpress.com/
If you visit any recent post like this one - http://twentytwelvedemo.wordpress.com/2012/03/28/road-trips/
The recent post widget on right sidebar include this post in recent 5 post. We could just exclude present post from the loop using code like this
<?php
global $post;
$args=array(
"numberposts"=>5,
"orderby"=>"post_date",
"post__not_in"=>array($post->ID)
);
$posts = get_posts($args);
foreach($posts as $post) {
setup_postdata($post);
?>
Most theme has it. If you are already in a post which is among recent 5, no point of showing it in the loop.
Attachments (2)
Change History (7)
#1
@
14 years ago
- Cc added
- Keywords has-patch added
- Summary Twenty Twelve: Exclude Present Post From Recent Post → `
21485.diff Adds a post__not_in value to the WP_Query. Not sure if using get_the_ID() in this instance is cheating :)
#2
@
14 years ago
- Component Bundled Theme → Widgets
- Summary ` → Exclude current post from Recent Posts widget
#3
follow-up:
↓ 4
@
14 years ago
If I had to guess, one reason why not to do this would be it would make caching harder.
#4
in reply to: ↑ 3
@
13 years ago
- Keywords ux-feedback removed
- Resolution → wontfix
- Status new → closed
- Version → 2.8
Replying to DrewAPicture:
21485.diff Adds a
post__not_invalue to theWP_Query. Not sure if usingget_the_ID()in this instance is cheating :)
get_the_ID() wouldn't be reliable on an archive, search or page for posts..
Replying to nacin:
If I had to guess, one reason why not to do this would be it would make caching harder.
Agreed the current post would not be excluded if the cache returned then if the cache was built without the current post then on other pages it would be missing. The only alternative I can think of is to add an additional post to the query args and check in the loop for the existing id then continue if found. Even that seams kind of hackish but would work.
I'm closing as wontfix as we can let theme developers do this on their own using the widget_posts_args filter.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Excludes current post