Filtering out Media Items from “Select post/page” Bricks control

The dropdown that appears after choosing “Internal post/page” when setting a link in Bricks shows media (attachment) items besides Pages, Posts and other CPTs.

If you want to remove the Media attachment items from appearing in this list, an undocumented filter called bricks/helpers/get_posts_args can be used.

Add the following in child theme‘s functions.php or a code snippets plugin:

add_filter( 'bricks/helpers/get_posts_args', function ( $args ) {
	$post_types = get_post_types( [ 'exclude_from_search' => false ] );

	// exclude attachment
	unset( $post_types['attachment'] );

	$args['post_type'] = $post_types;

	return $args;
});

Tested in Bricks 1.9.1.1.

Instant access to 390+ Bricks code tutorials with BricksLabs Pro

1 comment

  • Joe Fletcher

    To also exclude Bricks Templates from the Link To dialog (almost never need to link to templates), add:

    // exclude Templates
    unset( $post_types['bricks_template'] );

Leave your comment