Skip to:

Opened 3 years ago

Closed 3 years ago

#8488 closed enhancement (fixed)

Support date queries for members, groups and sites

Reported by: r-a-y's profile r-a-y Owned by: imath's profile imath
Milestone: 10.0.0 Priority: normal
Severity: normal Version:
Component: Core Keywords: has-patch dev-reviewed


We already support date queries for the activity and notification loops. Let's introduce date queries for the rest of our component loops -- members, groups and sites!

As I began adding date query to these components, there are two things I wanted to address:

  1. For our existing date query integrations, we manually strip the initial 'AND' SQL clause created by WP_Date_Query


This is a little messy. WP_Date_Query has seen some improvements to abstract some of this behavior.

So in the attached patch, I've modified our BP_Date_Query class so we can choose to prepend the AND SQL operator if we wanted to. See BP_Date_Query::__construct() for the new $prepend_and function argument, which I've defaulted to false. The only time we set this to true is for the sites component, which uses a messy SQL clause.

I've also created a new utility static method, BP_Date_Query::get_where_sql(). This is to be used where we want to initialize a new date query. See the new date query additions to members, groups and sites.

  1. Blogs component needs some love to use array as a function argument

Similar to what we did with the members component in #3797, I wanted to do the same thing for the blogs loop. So that's what I did here.

I've also cleaned up the PHPDoc as well.

Now that we've gotten that out of the way, let me explain how date queries will work in each of the components:

  • For members, we will only allow date queries if the $type in bp_has_members() is either active, newest, random or online.
  • For groups, we will only allow date queries if the $type in bp_has_groups() is either active or newest.
  • For sites, we will only allow date queries if the $type in bp_has_blogs() is either active or newest.

This is done because these types use a date to compare against. The other types like alphabetical or popular do not make much sense to use a date query with.

I've also added some unit tests for each component as well. Let me know what you think.

Attachments (2)

8488.01.patch (46.4 KB) - added by r-a-y 3 years ago.
8488.02.patch (56.6 KB) - added by imath 3 years ago.

Download all attachments as: .zip

Change History (7)

3 years ago

#1 @imath
3 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 9.0.0

Hi @r-a-y

I haven't tested it yet, but I believe it's a great idea. Thanks for working on it.

#2 @imath
3 years ago

  • Milestone changed from 9.0.0 to Up Next

Hi @r-a-y

I'm really sorry I couldn't find the time to test your patch. We've decided 9.0.0 would be a short development cycle focused on Widget Blocks (as 5.8 is introducing new features about this area).

Let's have date queries ready for 10.0.0 !!

#3 @imath
3 years ago

  • Milestone changed from Up Next to 10.0.0

Let's try to progress on it during 10.0.0 dev cycle.

3 years ago

#4 @imath
3 years ago

  • Keywords dev-reviewed added

Hi @r-a-y

I just had a deeper look at the patch. I've run the unit tests successfully and edited some parts (minor edits to improve WP Coding Standards compliance + updated @since to 10.0.0).

I seems promising, if you're confident with the patch, don't hesitate to commit it 👍

#5 @imath
3 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 13184:

Support date queries for Members, Groups and Sites

According to components, date queries can be restricted to a limited list of loop types:

  • For Members, the $type parameter in bp_has_members() needs to be either active, newest, random or online.
  • For Groups, the $type parameter in bp_has_groups() needs to be either active or newest.
  • For sites, the $type parameter in bp_has_blogs() needs to be either active or newest.

Props r-a-y

Fixes #8488

Note: See TracTickets for help on using tickets.