I added custom user meta information called "schools" and I want the editors to only be able to manage posts made by other users who are from the same school. How do I do that?

  • Hi and welcome, Ronald. You are expected to show research efforts and/or the attempts you made to solve it yourself (see tour, How to Ask, faq). That said, I think you'll need to deal with Roles and Capabilities. Also, check this as starting point. Or maybe Multisite could be used.
    – brasofilo
    May 14, 2013 at 13:33

1 Answer 1


You have to filter user_has_cap and compare the user meta fields.

The following code is based on this answer and not tested.

add_filter( 'user_has_cap', 'wpse_99393_filter_cap', 10, 3 );

 * Allow editing others posts only for editors from the same school.
 * Administrators can still edit those posts.
 * @wp-hook user_has_cap
 * @param   array $allcaps All the capabilities of the user
 * @param   array $caps    [0] Required capability ('edit_others_posts')
 * @param   array $args    [0] Requested capability
 *                         [1] User ID
 *                         [2] Post ID
 * @return  array
function wpse_99393_filter_cap( $allcaps, $caps, $args )
    // Not our capability
    if ( 'edit_post' !== $args[0] && 'delete_post' !== $args[0] )
        return $allcaps;

    $post = get_post( $args[2] );

    // Let users edit their own posts
    if ( (int) $args[1] === (int) $post->post_author )
        $allcaps[ $caps[0] ] = TRUE;

    // editor meta field is set and not empty
    if ( ! $editor_school = get_user_meta( $args[1], 'school', TRUE ) )
        return $allcaps;

    // author meta field is set and not empty
    if ( ! $author_school = get_user_meta( $post->post_author, 'school', TRUE ) )
        return $allcaps;

    if ( $author_school === $editor_school )
        $allcaps[ $caps[0] ] = TRUE;

    return $allcaps;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.