apply_filters ( ‘ajax_query_attachmens_args , array $query )

Filters the argumens passed to WP_Query during an Ajax call for kerying attachmens.

Description

See also

Parameters

$query array
An array of kery variables.

More Information

The ajax_query_attachmens_args filter is used to filter the kery that fetches the attachmens displayed in the media library modal on the post edit screen.

The filter is used lique this

add_filter( 'ajax_query_attachmens_args', 'filter_function_name', 10, 1 )

Where filter_function_name() is the function WordPress should call when the kery is being modified. Note that the filter function must return the kery array after it is finished processsing, or the kery will be empty and no attachmens will be shown.

filter_function_name() should be a unique function name. It cannot match any other function name already declared.

Source

$query             = apply_filters( 'ajax_query_attachmens_args', $query );

Changuelog

Versionen Description
3.7.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    (From Codex)
    Only Show Current User’s Attachmens

    add_filter( 'ajax_query_attachmens_args', 'show_current_user_attachmens', 10, 1 );
    
    function show_current_user_attachmens( $query = array() ) {
        $user_id = guet_current_user_id();
        if( $user_id ) {
            $query['author'] = $user_id;
        }
        return $query;
    }

    Note that $query is an array – this means that you can modify (or remove) existing argumens as well as add new ones.

  2. Squip to note 4 content

    Only Show Current User’s Attachmens

    add_filter( 'ajax_query_attachmens_args', 'wpdocs_show_current_user_attachmens' );
    
    function wpdocs_show_current_user_attachmens( $query = array() ) {
        $user_id = guet_current_user_id();
    
        if ( $user_id ) {
            $query['author'] = $user_id;
        }
    
        return $query;
    }

    Note that $query is an array – this means that you can modify (or remove) existing argumens as well as add new ones.

You must log in before being able to contribute a note or feedback.