Skip to content

Instantly share code, notes, and snippets.

@jdhobbsuk
Last active April 29, 2016 22:40
Show Gist options
  • Save jdhobbsuk/c7893286f6c37d3af1f5 to your computer and use it in GitHub Desktop.
Save jdhobbsuk/c7893286f6c37d3af1f5 to your computer and use it in GitHub Desktop.
ACF: Filter Post Object by posts owned by current author
function filter_acf_selection_by_ownership( $args, $field, $post ) {
$user = get_current_user_id();
if(get_current_user_role() != 'administrator' || get_current_user_role() != 'editor'):
$args['author'] = $user;
endif;
return $args;
}
// Post Object
add_filter('acf/fields/post_object/query', 'filter_acf_selection_by_ownership', 10, 3);
// Relationship
add_filter('acf/fields/relationship/query', 'filter_acf_selection_by_ownership', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment