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.

Get access to all 525 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

 

Related Tutorials..

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

This tutorial will explain how to enable the AJAX filter with an infinite scroll query loop container, how to add a sorting function, how to…
Categories:
Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags: