[wp-hackers] WP_Query filter posts by role
kevinjohngallagher at hotmail.com
Wed Sep 5 22:28:50 UTC 2012
I think this is a great example of where the 1 to 1 relationship of WP > User is not as flexible for today's market as it could be.The binary segmentation of Logged in / Logged out works for blogs, but as soon as you move away from that you start to hit issues.bbPress and buddyPress are great examples.
Just my two cents.
+44 (0) 7788 718382
KevinjohnGallagher at hotmail.com
> From: jer at simianuprising.com
> Date: Tue, 4 Sep 2012 13:21:36 -0400
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] WP_Query filter posts by role
> On Mon, Aug 27, 2012 at 5:51 AM, Filippo Pisano <filippo.pisano at gmail.com>wrote:
> > is there a way to filter all posts written by users with specific roles
> > (editors, authors etc)?
> There is no WP_Query parameter that will do what you want, so your only
> option is probably to use the posts_from and posts_where filters to add in
> custom SQL.
> Users' roles are stored in the wp_usermeta table of the database as a
> serialzed array of all their roles and/or individual capabilities. This
> means you will almost definitely NOT want to access them directly. Instead
> I propose that what you'd want to do is generate an array with all users in
> a given role, then in the posts_where filter add a clause that fetches
> posts from any of the authors from that array.
> Not a simple solution but your problem is fairly unique. User roles are
> intended for use in controlling access permissions rather than for marking
> content sections of your site (though your issue points out how such a
> 'content groups' need often comes up).
> Jeremy Clarke
> Code and Design • globalvoicesonline.org
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers