Home Forums ACF PRO Restrict Media Library acf_form


Restrict Media Library acf_form

  • Hi there,

    I’m using `acf_form’ to create a front end form where users can create posts. To do so, I have a WYSIWYG fields, which accordingly I have set to show media upload buttons.

    What I would like to do is restrict the media library to only files either 1) files uploaded by the current user – or – 2) files already attached to a post.

    In other words, make the WYSIWYG field work like the standard ACF image field type where there is a ‘Library / Limit the media library choice’ option.

    Thanks in advance!

  • Hi @ryandorn

    You would probably need to modify the query yourself.
    Here’s an example that limits the query when visiting the uploader in admin. You need to do something like this but for when it’s triggered on your frontend form.

    //Manage Your Media Only
    function mymo_parse_query_useronly( $wp_query ) {
        if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
            if ( !current_user_can( 'update_core' ) ) {
                global $current_user;
                $wp_query->set( 'author', $current_user->id );
    add_filter('parse_query', 'mymo_parse_query_useronly' );
  • Hi Jonathan,

    Thanks for the response!

    That code didn’t work for me straightaway so I keep digging and happened to stumble across this, which is working for me straight out of the box.

    add_filter( 'posts_where', 'devplus_attachments_wpquery_where' );
    function devplus_attachments_wpquery_where( $where ){
    	global $current_user;
    	if( is_user_logged_in() ){
    		// we spreken over een ingelogde user
    		if( isset( $_POST['action'] ) ){
    			// library query
    			if( $_POST['action'] == 'query-attachments' ){
    				$where .= ' AND post_author='.$current_user->data->ID;
    	return $where;

    Thanks again!

  • Hi @ryandorn

    Yeah that was just some code to get you going 😉
    Glad you found the solution!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Restrict Media Library acf_form’ is closed to new replies.