Documentation

gwp_gview_advanced_filter

The gwp_gview_advanced_filter merge tag is designed to dynamically filter entries in GravityViews, leveraging user meta properties that store JSON-encoded arrays of filter values. This functionality requires the GravityKit Advanced Filters extension to be active.

Purpose

This merge tag allows you to create dynamic and user-specific view content by parsing the merge tag within GravityView’s advanced filter settings and replacing them with values pulled from user meta data or form entries that can be matched to the user. This enables the dynamic generation of OR-filters based on a list of values associated with a user.

Variants and Usage Examples

The gwp_gview_advanced_filter merge tag supports the following variants for fetching user-specific data:

{gwp_gview_advanced_filter:user_meta_key:your_meta_key}

This variant fetches a JSON-encoded array from a specified user meta key.

Example: If a user meta key allowed_tier_types stores ["TIER1","TIER2"], using {gwp_gview_advanced_filter:user_meta_key:allowed_tier_types} in a GravityView filter condition will dynamically generate two OR-filters:

  • 'Tier' is 'TIER1'
    OR
  • 'Tier' is 'TIER2'
Screenshot of the Advanced Filter settings using the {gwp_gview_advanced_filter:user_meta_key:your_meta_key} merge tag to create OR filters based on the current user's user_meta value.
Screenshot of the Advanced Filter settings using the {gwp_gview_advanced_filter:user_meta_key:your_meta_key} merge tag. This will dynamically create OR filters based on the current user’s user_meta value.
{gwp_gview_advanced_filter:user_email:gwp_get_matched_entry_value form_id=1 match_id=2 return_id=3}

This variant uses the current user’s email to find a matching entry in another form and return a specific field value.

{gwp_gview_advanced_filter:user_login:gwp_get_matched_entry_value form_id=1 match_id=2 return_id=3}

This variant uses the current user’s login name to find a matching entry in another form and return a specific field value.

Note: When using gwp_get_matched_entry_value within gwp_gview_advanced_filter, the inner merge tag format is adjusted for processing.

For instance, {gwp_gview_advanced_filter:user_email:gwp_get_matched_entry_value will be internally converted to {gwp_get_matched_entry_value value='current-user@email.com'} before processing.

Requirements

  • GravityKit Advanced Filters extension must be active for this merge tag to function.
  • The retrieved value from the user meta key should be a valid JSON-encoded array for proper filtering.

How it Works

The filter_merge_tags method intercepts existing GravityViews filters. It iterates through the conditions, identifies the gwp_gview_advanced_filter merge tag. Then it extracts its parameters, and fetches the relevant user data (from user meta, email, or login). If the data is a JSON-encoded array, it decodes it and dynamically expands the single filter condition into multiple OR-conditions, effectively applying a flexible set of filters based on user-specific attributes.

Advanced Merge Tagsv1.9.2

To use the functionalities described in this documentation, you'll need to get the GravityWP - Advanced Merge Tags add-on.

Read more