Tell us what you are trying to do?
Create a view that displays a list of new subscribers in the last 7 days
Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/views/date-filters/
The documentation page for Date filters describes "listing all users registered for the past year, and more," but I don't see any date options in the query filter dropdown menu. Am I missing something?
Hello and thank you for contacting the Toolset support.
I can see that this documentation article does not explain how to list users by date. I tried to find out how, but I couldn't.
Let me approach our 2nd Tier about this and get back to you.
On the meantime, maybe the following plugin can help: https://wordpress.org/plugins/users-by-date-registered/
Thank you. I have several custom user roles, so I'd rather just use Toolset, or even a php snippet than installing another plugin.
My apologies for the late reply but I do not work on Sundays and Mondays.
I run a test locally and we can use the wpv_filter_user_query filter and alter the view's query filter. Check the following example, it displays uses that are created after a given date "2020-01-07 15:27:31"
add_filter( 'wpv_filter_user_query', 'my_users_registered_this_year', 99, 3 );
function my_users_registered_this_year( $query_args, $view_settings, $view_id ) {
// Execute this only for the view 15
if ( $view_id == 15) {
$query_args['date_query'] = array(
array(
'after' => '2020-01-07 15:27:31',
'inclusive' => true,
),
);
}
return $query_args;
}
More about the hook here https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query
Check these StackOverflow questions, they might also help:
- https://wordpress.stackexchange.com/questions/174700/wp-user-query-users-by-registered-date
- https://wordpress.stackexchange.com/questions/219284/display-page-only-if-user-registered-before-a-specific-date
I hope this helps. Let me know if you have any questions.
Thanks Jamel. So, instead of a specific date, if I needed to filter for users registered in the past 7 days do I use 'PAST_DAY(7)' instead of the timestamp '2020-01-07 15:27:31'?
Also I believe there is an error in your Date Filters documentation: https://toolset.com/documentation/user-guides/views/date-filters/
• PAST_DAY(int) (time at 00:00 on the following day)
This should actually be the PREVIOUS day
I do not believe you can use "PAST_DAY" in the example code below. That's a Toolset function that can only be used inside Toolset views. The code, instead, will be added to the theme's functions.php file or to Toolset->Settigns->Custom Code. So you will have to remove the 7 days programmatically.
Check this article about substructing dates hidden link
And keep in mind that the date in the code should follow the format(eg. '2020-01-07 15:27:31')
Check the date format function hidden link
Thank you for reporting the error on the documentation, I escalated to our documentation team and it will be fixed soon.
Thank you, I will give that a try. Could I suggest adding the user registration Date field to the built-in query filters in a future update?