28th Sep '23
/
1 comment

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 612 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 Add a Custom Control Field to an Element in Bricks

How to Add a Custom Control Field to an Element in Bricks

In this tutorial, we'll learn how to add a custom control field to an element and dynamically change a CSS property inside the builder. Introduction…
Categories:
Tags:
How to create filters with IsotopeJS in Bricks (Part 1)

How to create filters with IsotopeJS in Bricks (Part 1)

This tutorial series will explore the IsotopeJS library's features inside the Bricks ecosystem.
Categories:
Pro
How to programmatically add a class to an element in Bricks

How to programmatically add a class to an element in Bricks

This Pro tutorial shows how a dynamic class can be added to a query loop element in Bricks programmatically. Let's take an example where posts…
How to Exclude Elements from Bricks Editor

How to Exclude Elements from Bricks Editor

Bricks has a handy bricks/builder/elements filter using which the available elements that show up after clicking + (or ⌃/⌘ + ⇧ + E) in the…
Categories:
Tags: