Make WordPress Core

Opened 8 years ago

Last modified 8 years ago

#37837 new feature request

Extend WP_Query author parameters to filter by role

Reported by: jadpm's profile jadpm Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: Query Keywords:
Focuses: Cc:

Description

WP_Query contains a series of author parameters (author', ' author_name', ' author__in', and authornot_in` as documented on the Codex).

It wpould be nice to add author_role__in and maybe author_role__not_in as valid parameters, and be able to also query for posts given one or a set of user roles. I can see a lot of usages, and this has indeed been asked inside the community in some places, although I could not find a Track dedicated ticket.

AFAIK, this would require the WP_Query database interaction to include the usermeta table, which can be expensive by default, and add a LIKE statement against the wp_capabilities usermeta field value, which is also expensive by default. So this might introduce performance problems and be discarded because of that. But otherwise, I would like that we consider this as a possible feature to add.

Change History (1)

#1 @nitya99
8 years ago

Can't imagine wp_query doesn't query posts by user role. All the user generated directory or blog websites I builds (different user roles with different capabilities), has this limit.

We can't just get all the 5000+ user ids by role and then query the posts by those user ids.

I think query posts by author role must be added to the core wp_query.

Note: See TracTickets for help on using tickets.