---
title: "Modifying the entries displayed in a View"
date: 2026-04-23
author: "GravityKit"
link: "https://www.gravitykit.com/docs/gravityview/advanced/modifying-the-entries-displayed-in-a-view/"
---

This code is meant for **developers only.** If you are just trying to filter View results, please use the [Advanced Filter extension](https://www.gravitykit.com/docs/gravityview-pro/advanced-filter/getting-started-with-the-advanced-filtering-extension/) instead, which doesn't require any coding skills.

## Choosing the right hook

GravityView gives you three hooks for changing which entries a View shows, and each one acts at a different stage of the query. As a rule of thumb, use the earliest hook that can express your logic: earlier hooks let GravityView keep the entry count and pagination correct for you.

**`gravityview_fe_search_criteria`** (best for field conditions). Runs before the query. Append your conditions to the `field_filters` array, for example to filter by the logged-in user's ID. Because it runs pre-query, entry totals and pagination stay correct automatically.

```
add_filter( 'gravityview_fe_search_criteria', function ( $criteria, $form_id, $args ) {
    $criteria['field_filters'][] = array(
        'key'   => '5', // The field to filter on.
        'value' => get_current_user_id(),
    );
    return $criteria;
}, 10, 3 );
```

**`gravityview/view/query`**. Runs before the query executes and hands you the `GF_Query` object by reference, so you can modify the SQL directly, such as an `IN (...)` list of IDs or a join.

```
add_action( 'gravityview/view/query', function ( $query, $view, $request ) {
    // $query is a \GF_Query; modify it in place.
}, 10, 3 );
```

**`gravityview/view/entries`**. Runs after the entries are fetched and gives you the resolved entry collection to filter in PHP. It is the most flexible option, but because it runs post-fetch you are responsible for keeping the entry total and pagination in sync. Reach for it only when the logic cannot be expressed in SQL, as shown in the example below.

GravityView provides the `gravityview/view/entries` filter which can be used to modify entries before they are displayed on the View.

Below is a code snippet that can be used as a boilerplate for custom modifications:

```
add_filter( 'gravityview/view/entries', 'gv_filter_gravityview_view_entries', 10, 3 );

/**
 *
 * @param GVEntry_Collection $entries The entries for this view.
 * @param GVView $view The view.
 * @param GVRequest $request The request.
 *
 * @return GVEntry_Collection
 */
function gv_filter_gravityview_view_entries( $entries, $view = null, $request = null ) {

	// Only filter entries for View #123
	if( 123 !== $view->ID ) {
		return $entries;
	}

	if( ! $entries instanceof GVEntry_Collection ) {
		return $entries;
	}

	// There's no way to remove entries from a collection; instead, we just create a new one
	$return = new GVEntry_Collection();

	foreach( $entries->all() as $entry ) {

		// Your custom code here!
	}

	return $return;
}
```

```
add_filter( 'gravityview/view/entries', 'gv_filter_gravityview_view_entries', 10, 3 );

/**
 *
 * @param GVEntry_Collection $entries The entries for this view.
 * @param GVView $view The view.
 * @param GVRequest $request The request.
 *
 * @return GVEntry_Collection
 */
function gv_filter_gravityview_view_entries( $entries, $view = null, $request = null ) {

	// Only filter entries for View #123
	if( 123 !== $view->ID ) {
		return $entries;
	}

	if( ! $entries instanceof GVEntry_Collection ) {
		return $entries;
	}

	// There's no way to remove entries from a collection; instead, we just create a new one
	$return = new GVEntry_Collection();

	foreach( $entries->all() as $entry ) {

		// Your custom code here!
	}

	return $return;
}
```

[How to add this code snippet to your website](https://www.gravitykit.com/docs/gravityview/customizing-your-views/where-to-put-code-samples/).