[Plugin: Network Latest Posts] "Time Frame in Days" on the widget
-
Hi Jose
I’m using your plugin to display the NLP widget between the post and its comments. The “Time Frame in Days” setting doesn’t seem to work as older posts are displayed than specified.
Is there a way I can test this with a normal text widget and a shortcode?
Thanks!
Kobus
-
Hello Kobus,
Yes actually this is my fault, I wrongly stated that time frame in days was a value related to posts but it is actually related to blogs. It will find blogs updated between the time frame specified there and then it will pull the posts from them.
The get posts hook doesn’t allow time frame parameters so there is no “easy” way to do what you want unless it’s done manually.
I will eventually work on a solution, right now the time frame will only work for blogs instead of posts.
Thanks for pointing this out, sorry I can’t propose a quick solution for this. I will keep it in mind as a feature request.
Cheers.
Thanks for the reply Jose!
Hi Jose
I’m running a news site with 25 new posts daily. The news gets old very quickly so I did some digging into this issue.
I found the following code that adds a filter to the
query_posts
function to display the latest posts from the past 2 days (taken from the WordPress Forum):// Create a new filtering function that will add our where clause to the query function filter_where( $where = '' ) { // posts 1 to 2 days old $where .= " AND post_date >= '" . date('Y-m-d', strtotime('-2 days')) . "'" . " AND post_date < '" . date('Y-m-d') . "'"; return $where; } add_filter( 'posts_where', 'filter_where' ); query_posts( 'post_type=post&posts_per_page=-1&caller_get_posts=1' ); if ( have_posts() ) { while ( have_posts() ) { the_post(); $this_date = get_the_time('Y-m-d'); if (++$seen[$this_date] > 2) continue; // Put the code to display one post here echo "<h2>";the_title();echo '</h2>'; echo the_time('F jS, y'); } } else { // Code for no posts found }
I see in your plugin that you use
get_posts($args)
on line 386 ofnetwork-latest-posts.php
. Is there a way to add the filter to$args
? According to this tread on WordPress Hackers, using'suppress_filters' => false
isn’t always a good idea.I realise I’m totally out of my depth. By the way, thank you for the clear comments in your code!
Regards
KobusHello Kobus,
Yes it is possible to affect the query suppressing filters, the problem here is we are not echoing results directly and we are pulling multiple values from different blogs, I did some quick tests with filters but they don’t work, maybe it’s because the way the requests are being made.
Suppressing filters isn’t a good idea because it affects all queries made after the filter so you may get unexpected results, under controlled environments I don’t see this as a problem, if you want your filter to affect all queries it’s useful though.
I will do more tests as soon as I have the time and if I find something interesting I will let you know.
Cheers.
Thank you Jose!
- The topic ‘[Plugin: Network Latest Posts] "Time Frame in Days" on the widget’ is closed to new replies.