Home › Forums › ACF PRO › Gallery field hide media library › Reply To: Gallery field hide media library
What type of users will be using this front end form? Have you tried logging into your site as that type of user? Does that type of user have access to the media library? If not then the gallery field isn’t going to work for them and you’ll need to provide them with an alternate to the gallery.
Assuming that they do have access to the media library you can limit the images that they see to only the ones they uploaded by using a pre_get_posts filter.
add_filter('pre_get_posts', 'limit_gallery_to_user');
function limit_gallery_to_user($query) {
if (is_admin() ||
!isset($query->query_vars['post_type']) ||
$query->query_vars['post_type'] != 'attachment') {
return;
}
$user_id = get_current_user_id();
$query->set('author', $user_id);
}
If they don’t have access to the medial library and the gallery does not work you will probably need to use a repeater field with image fields and then transfer the images to the gallery using an acf/save_post filter.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.