Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_edit_attachments_query_vars

Function Description:

Returns the query variables for the current attachments request.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Adding a custom query var to the attachments query
function custom_attachments_query_vars( $query_vars ) {
    $query_vars[] = 'custom_var';
    return $query_vars;
}
add_filter( 'wp_edit_attachments_query_vars', 'custom_attachments_query_vars' );
// Example 2: Removing a default query var from the attachments query
function remove_default_query_var( $query_vars ) {
    $key = array_search( 'orderby', $query_vars );
    if ( false !== $key ) {
        unset( $query_vars[ $key ] );
    }
    return $query_vars;
}
add_filter( 'wp_edit_attachments_query_vars', 'remove_default_query_var' );
// Example 3: Modifying the default query vars for attachments
function modify_attachments_query_vars( $query_vars ) {
    $query_vars['posts_per_page'] = 10;
    return $query_vars;
}
add_filter( 'wp_edit_attachments_query_vars', 'modify_attachments_query_vars' );