Skip Navigation

[Resolved] Filter User list by registration date

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to display the site users in a view based on their registration date and the current date.

Solution:
Toolset does not have a built-in way to query users by registration date. The solution will need custom code.
Check an example in this reply https://toolset.com/forums/topic/filter-user-list-by-registration-date/#post-1713595

Relevant Documentation:

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by Dan Kitsmiller 4 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#1710635

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?

#1711081

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/

#1711339

Thank you. I have several custom user roles, so I'd rather just use Toolset, or even a php snippet than installing another plugin.

#1713595

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.

#1718477

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

#1720593

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.

#1721275

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?