My objective is to filter out the posts of the post's publish date is equal to the post's modified date or where the post's modified date in within 5 minutes of the post 's published date. Thus I would only get the posts listed with do not have the post's modified date equal or within 5 minutes to the post's published date.
Hi Beda,
Thank you for your prompt reply and I would say you gave me exactly what I initially conceptualized. In fact you have actually taught me how to pass arguments through wpvshortcode. Many thanks for that.
But actually I am still missing something to achieve what is required for my project. I am sure you if the above method has not worked for me, you will be able to point me to the right direction.
I'll explain you my requirement. I am trying to list the entries of a custom post type "i.e. Downloads" into two columns, first column list the posts based on their "Initial Published Date" and the second column lists them based on the "Date they were last modified".
Listing the posts based on their initial Published date is pretty straight forward, but when sorting them for the second column for the "Date they were last modified" by sorting them with their "Modified_Date" also includes the newly published posts. I am looking for a method to exclude the newly published posts form this post listing.
For this I cam up with the idea to compare the post published_date with the post modified_date and if the difference is less than 5 minutes, then such posts should be filtered out of the listing.
Somehow am not able to achieve it. I am sure you have a much better idea than comparing the dates.
Beda is working on another project, so let me take over here if that's okay.
I read your update and I'm not completely sure I understand the requirement, so let me clarify that before I continue.
When you talk of two columns, I wasn't sure whether you mean displaying the results from a single View in two columns (which you could sort as required) as shown in the screenshot, or whether you meant you are displaying two Views (which happen to be displayed in columns), the first View displays all download posts (ordered by publish date) and the second View displays only those download posts which have been modified (i.e. the post modified date does not equal the publish date).
That would mean duplicates because the first column shows all posts, unless you want to exclude the posts which appear in the second column from the first.
Can you clarify the requirement and then I'll help you set it up.
Hi Nigel,
Its great to have you, you helped me very precisely with my last support ticket, will be great if you can guide me on this one.
The problem is not displaying the columns, actually I was trying to elaborate in depth, but forgive me for going into unnecessary details.
I am simply looking to display the list of posts using Views which are sorted by the modified date, but such a view is including the newly added ones as well which I do not need to be listed in this view.
I came up with the idea that filtering out the posts which have the difference of 5 minutes between the publish_date and the modified_date can solve this, but somehow the above solution given by Beda to achieve this is not still not filtering out the posts for me. I am assuming that possibly I am making conceptual mistakes in comparing both the dates or may be the above method provided by Beda requires some modification to achieve what I need.
Hope this clarifies the problem. Thanks for any help.
It's not very straightforward to use the WP_Query arguments to construct a query where you can compare the post_date and post_modified fields, so I suggest creating a View which will display all possible posts and then using the wpv_filter_query_post_process API filter to manipulate the results and remove the unwanted ones.
I did that with the following code:
function tssupp_modified_posts( $query, $view_settings, $view_id ){
if ( $view_id == 105 ) {
$query_posts = $query->posts;
foreach ($query_posts as $key => $query_post) {
if ( $query_post->post_date == $query_post->post_modified ) {
// post has not been modified, remove from results
unset( $query_posts[ $key ] );
$query->post_count--;
$query->found_posts--;
}
}
// reindex and update results
$query->posts = array_values( $query_posts );
}
return $query;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_modified_posts', 101, 3 );
It will only show posts which have been modified. You should just need to edit the view id.
Absolutely what I needed. It really works. Thanks for everything.
However I just have one small issue with that if you could help that's great if not, I'll be good with the code you have provided. The issue is that, the view that I have created, is suppose to list only 5 updated posts. Now In-case when there are only new posts being added, the 5 view returns "No post found" simply because all the last 5 posts were new additions and not the modifications. Is there a way to make this function smart and instead of counting those new additions, simply omit the results in a way that it does not affect the listing at all using this function?