We created a view and we need to filter the posts only with publishing date only after the last 4 months.
We already created a filter using the parameters in the enclosed screenshot but what happen when we will have the last 4 months in between 2 years (i.e. in January the 4 latest months will spread also in the former year).
Any help on this?
Thanks
Franco
Hi Franco,
The best way to resolve this is by using a date query as our date query filters can be inconsistent at times. Add the following to the Toolset custom code settings at Toolset -> Settings-> Custom Code and activate it. This should ensure that you're only getting the posts that were published after 4 months ago.
function tssupp_date_filter( $query_args, $view_settings, $view_id ){
if ( 123 == $view_id ) { // Edit View ID
$query_args['date_query'] = array(
array(
'column' => 'post_date_gmt',
'after' => '4 months ago'
)
);
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'tssupp_date_filter', 101, 3 );
Replace 123 with the ID of your view.
Please let me know if this helps.
Thanks,
Shane
Hi Shane, I did what you suggested but the filter seems not working, I enclose a JPG with all settings and script that I created and as you see the ticker shows posts with a date previous than 4 months from today
Please let me know what could be the reason.
thanks
Franco
Hi Franco,
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please where applicable please provide me with a link to an example page where I can see the issue.
I've enabled the private fields for your next response.
Thanks,
Shane
Hi Shane, you can login to the admin area of the website with the following credentials
Please do not update plugins or themes since we do not have a backup copy of the website ( checked the backup checkbox just because it is the only way to send you the message).
The page where the view is placed is:
hidden link
Thanks
Franco
Hi Franco,
I checked the site for you but it appears that everything is working as intended.
I'm not seeing any issues at all with the date filter. All the correct values are being returned.
Thanks,
Shane
Hi Shane,
if you look at the following URL
hidden link
you notice that the ticker elements appear also before 4 months from today (I still see posts from June 24 and earlier (see screenshot). those post shall not appear at all since the ticker shall display only the latest 4 months posts
Franco
Hi Franco,
Perhaps view the page in a different browser as this is what i'm seeing. See Screenshot.
I removed the conveyor div temporarily to illustrate what i'm seeing. Notice there are no posts that are breaking query filter specifications.
Thanks,
Shane
My issue is resolved now. Thank you!
Franco