Skip to main content

GravityView_Widget_Search

Source: includes/widgets/search-widget/class-search-widget.php:27

Details

  • Kind: class
  • Namespace: (global)
  • Extends: GV\Widget

Methods

MethodDescription
getInstance()
add_reserved_args()
get_search_method()Returns the search method
get_input_types_by_field_type()Get the input types available for different field types
get_search_input_labels()Get labels for different types of search bar inputs
add_scripts_and_styles()Add script to Views edit screen (admin)
register_no_conflict()Add admin script to the no-conflict scripts allowlist
get_searchable_fields()Ajax
render_searchable_fields()Generates html for the available Search Fields dropdown
get_search_input_types()Assign an input type according to the form field type
add_no_permalink_fields()Display hidden fields to add support for sites using Default permalink structure
filter_entries()Calculate the search criteria to filter entries
gf_query_filter()Filters the \GF_Query with advanced logic.
prepare_field_filter()Prepares the field filters to GFAPI.
get_date_field_format()Get the Field Format form GravityForms
get_formatted_date()Format a date value
add_template_path()Include this extension templates path
render_frontend()Renders the Search Widget
get_search_class()Get the search class for a search form.
get_search_form_action()Calculate the search form action
the_clear_search_button()Output the Clear Search Results button
add_datepicker_js_dependency()Require the datepicker script for the frontend GV script
add_datepicker_localization()Modify the array passed to wp_localize_script()
enqueue_datepicker()Enqueue the datepicker script
add_preview_inputs()If previewing a View or page with embedded Views, make the search work properly by adding hidden fields with
add_form_search_fields()Adds search fields for a specific form.
set_search_field_options()Add the settings for this field.
render_search_active_areas()Render the search areas.
render_available_search_fields()Render html for displaying available search fields.
record_search_field_context()Records the rendering context of a search field about to be rendered.
reset_area_recording()Resets the recorded areas for the next row.
add_search_area_settings_button()Renders a "Clear all fields" button in the View configuration.
add_search_area_settings()Registers the area settings for the search fields.
render_area_settings()Renders the settings for a search area.

Method Reference

getInstance()

public static function getInstance()

Returns

Source: includes/widgets/search-widget/class-search-widget.php:117

add_reserved_args()

public function add_reserved_args( $args )

Parameters

NameTypeDefaultDescription
$args

Returns

  • mixed

Since: 2.10

Source: includes/widgets/search-widget/class-search-widget.php:132

get_search_method()

public function get_search_method()

Returns the search method

Returns

  • string

Since: 1.16.4

Source: includes/widgets/search-widget/class-search-widget.php:190

get_input_types_by_field_type()

public static function get_input_types_by_field_type()

Get the input types available for different field types

Returns

  • array — [field type name] => (array|string) search bar input types

Since: 1.17.5

Source: includes/widgets/search-widget/class-search-widget.php:201

get_search_input_labels()

public static function get_search_input_labels()

Get labels for different types of search bar inputs

Returns

  • array — [input type] => input type label

Since: 1.17.5

Source: includes/widgets/search-widget/class-search-widget.php:263

add_scripts_and_styles()

public function add_scripts_and_styles( $hook )

Add script to Views edit screen (admin)

Parameters

NameTypeDefaultDescription
$hookmixed

Source: includes/widgets/search-widget/class-search-widget.php:305

register_no_conflict()

public function register_no_conflict( $allowed )

Add admin script to the no-conflict scripts allowlist

Parameters

NameTypeDefaultDescription
$allowedarrayScripts allowed in no-conflict mode

Returns

  • array — Scripts allowed in no-conflict mode, plus the search widget script

Source: includes/widgets/search-widget/class-search-widget.php:346

get_searchable_fields()

public static function get_searchable_fields()

Ajax

Returns the form fields ( only the searchable ones )

Returns

  • void

Source: includes/widgets/search-widget/class-search-widget.php:358

render_searchable_fields()

public static function render_searchable_fields( $form=null, $current='' )

Generates html for the available Search Fields dropdown

Parameters

NameTypeDefaultDescription
$formint | arraynull
$currentstring''(for future use)

Returns

  • string

Source: includes/widgets/search-widget/class-search-widget.php:388

get_search_input_types()

public static function get_search_input_types( $field_id='', $field_type=null )

Assign an input type according to the form field type

Parameters

NameTypeDefaultDescription
$field_idstring | int | float''Gravity Forms field ID
$field_typestringnullGravity Forms field type (also the name parameter of GravityView_Field classes)

Returns

  • string — GV field search input type ('multi', 'boolean', 'select', 'date', 'text')

See Also

  • admin-search-widget.js

Source: includes/widgets/search-widget/class-search-widget.php:435

public function add_no_permalink_fields( $search_fields, $object, $widget_args=[] )

Display hidden fields to add support for sites using Default permalink structure

Parameters

NameTypeDefaultDescription
$search_fields
$object
$widget_args[]

Returns

  • array — Search fields, modified if not using permalinks

Since: 1.8

Source: includes/widgets/search-widget/class-search-widget.php:479

filter_entries()

public function filter_entries( $search_criteria, $form_id=null, $args=[], $force_search_criteria=false )

Calculate the search criteria to filter entries

Parameters

NameTypeDefaultDescription
$search_criteriaarrayThe search criteria
$form_idintnullThe form ID
$argsarray[]Some args
$force_search_criteriaboolfalseWhether to suppress GF_Query filter, internally used in self::gf_query_filter

Returns

  • array

Source: includes/widgets/search-widget/class-search-widget.php:655

gf_query_filter()

public function gf_query_filter( &$query, $view, $request )

Filters the \GF_Query with advanced logic.

Drop-in for the legacy flat filters when \GF_Query is available.

Parameters

NameTypeDefaultDescription
&$query\GF_QueryThe current query object reference
$view
$request\GV\RequestThe request object
$this\GV\ViewThe current view object

Source: includes/widgets/search-widget/class-search-widget.php:977

prepare_field_filter()

public function prepare_field_filter( $filter_key, $value, $view, $searchable_fields, $get=[] )

Prepares the field filters to GFAPI.

The type post_category, multiselect and checkbox support multi-select search - each value needs to be separated in an independent filter so we could apply the ANY search mode.

Format searched values

Parameters

NameTypeDefaultDescription
$filter_keystringID of the field, or entry meta key
$valuestring$_GET/$_POST search value
$view\GV\ViewThe view we're looking at
$searchable_fieldsarray[]The searchable fields as configured by the widget.
$getstring[][]The $_GET/$_POST array.

Returns

  • array | false — 1 or 2 deph levels, false if not allowed

Since: 2.42

Source: includes/widgets/search-widget/class-search-widget.php:1478

get_date_field_format()

public static function get_date_field_format( GF_Field_Date $field )

Get the Field Format form GravityForms

Parameters

NameTypeDefaultDescription
$fieldGF_Field_DateThe field object

Returns

  • string — Format of the date in the database

Since: 1.10

Source: includes/widgets/search-widget/class-search-widget.php:1739

get_formatted_date()

public static function get_formatted_date( $value='', $format='Y-m-d', $value_format='Y-m-d' )

Format a date value

Parameters

NameTypeDefaultDescription
$valuestring''Date value input
$formatstring'Y-m-d'Wanted formatted date
$value_formatstring'Y-m-d'The value format. Default: Y-m-d

Returns

  • string

Since: 2.1.2

Source: includes/widgets/search-widget/class-search-widget.php:1770

add_template_path()

public function add_template_path( $file_paths )

Include this extension templates path

Parameters

NameTypeDefaultDescription
$file_pathsarrayList of template paths ordered

Source: includes/widgets/search-widget/class-search-widget.php:1787

render_frontend()

public function render_frontend( $widget_args, $content='', $context='' )

Renders the Search Widget

Parameters

NameTypeDefaultDescription
$widget_argsarray
$contentstring''
$contextstring | \GV\Template_Context''

Returns

  • void

Source: includes/widgets/search-widget/class-search-widget.php:1833

get_search_class()

public static function get_search_class( $custom_class='', $search_layout='horizontal' )

Get the search class for a search form.

Parameters

NameTypeDefaultDescription
$custom_classstring''Custom class to add to the search form
$search_layoutstring'horizontal'Search layout ("horizontal" or "vertical"). Default: "horizontal".

Returns

  • string — Sanitized CSS class for the search form

Since:

Source: includes/widgets/search-widget/class-search-widget.php:1905

get_search_form_action()

public static function get_search_form_action( $post_id=0 )

Calculate the search form action

Parameters

NameTypeDefaultDescription
$post_id0

Returns

  • string

Since:

Source: includes/widgets/search-widget/class-search-widget.php:1933

the_clear_search_button()

public static function the_clear_search_button()

Output the Clear Search Results button

Since: 1.5.4

Source: includes/widgets/search-widget/class-search-widget.php:1958

add_datepicker_js_dependency()

public function add_datepicker_js_dependency( $js_dependencies )

Require the datepicker script for the frontend GV script

Parameters

NameTypeDefaultDescription
$js_dependenciesarrayArray of existing required scripts for the fe-views.js script

Returns

  • array — Array required scripts, with jquery-ui-datepicker added

Source: includes/widgets/search-widget/class-search-widget.php:1971

add_datepicker_localization()

public function add_datepicker_localization( $localizations=[], $view_data=[] )

Modify the array passed to wp_localize_script()

Parameters

NameTypeDefaultDescription
$localizations[]
$view_dataarray[]View data array with View settings
$js_localizationarrayThe data padded to the Javascript file

Returns

  • array

Source: includes/widgets/search-widget/class-search-widget.php:1985

enqueue_datepicker()

public function enqueue_datepicker()

Enqueue the datepicker script

Returns

  • void

Source: includes/widgets/search-widget/class-search-widget.php:2034

add_preview_inputs()

public function add_preview_inputs()

If previewing a View or page with embedded Views, make the search work properly by adding hidden fields with

query vars

Returns

  • void

Since: 2.2.1

Source: includes/widgets/search-widget/class-search-widget.php:2129

add_form_search_fields()

public function add_form_search_fields( array $search_fields, int $form_id ): array

Adds search fields for a specific form.

Parameters

NameTypeDefaultDescription
$search_fieldsSearch_Field[]The fields.
$form_idintThe form ID.

Returns

  • Search_Field[] — The update fields.

Since: 2.42

Source: includes/widgets/search-widget/class-search-widget.php:2262

set_search_field_options()

final public function set_search_field_options( $options=[], $template_id='', $field_id='', $context='', $input_type='', $form_id=0 ): array

Add the settings for this field.

Parameters

NameTypeDefaultDescription
$optionsarray[]The original options.
$template_idstring''The template ID.
$field_idstring''The field ID.
$contextstring''The area ID.
$input_typestring''The (optional) input type.
$form_idstring | int0The form ID.

Returns

  • array — The updated options.

Since: 2.42

Source: includes/widgets/search-widget/class-search-widget.php:2346

render_search_active_areas()

public function render_search_active_areas( string $template_id, string $zone, array $data ): void

Render the search areas.

Parameters

NameTypeDefaultDescription
$template_idstringThe current slug of the selected View template.
$zonestringEither 'search-general' or 'search-advanced'.
$dataarray

Returns

  • void

Since: 2.42

Source: includes/widgets/search-widget/class-search-widget.php:2445

render_available_search_fields()

public function render_available_search_fields( ?int $form_id=0, ?string $section=null ): void

Render html for displaying available search fields.

Parameters

NameTypeDefaultDescription
$form_id?int0
$section?stringnull

Returns

  • void

Since: 2.42

Source: includes/widgets/search-widget/class-search-widget.php:2512

record_search_field_context()

public function record_search_field_context( string $field_type, string $key, array $option, array $settings, array $rendering ): void

Records the rendering context of a search field about to be rendered.

Parameters

NameTypeDefaultDescription
$field_typestringEither 'widget', 'field' or 'search'.
$keystringThe key of the settings field.
$optionarrayThe configuration of the settings field.
$settingsarrayAll the values for the current item being rendered.
$renderingarrayExtra rendering context added to the action.

Returns

  • void

Since: 2.42

Source: includes/widgets/search-widget/class-search-widget.php:2544

reset_area_recording()

public function reset_area_recording( $is_dynamic, $template_id, $type, $zone ): void

Resets the recorded areas for the next row.

Parameters

NameTypeDefaultDescription
$is_dynamicboolWhether the area is dynamic.
$template_idstringThe template ID.
$typestringThe object type (widget or field).
$zonestringThe render zone.

Returns

  • void

Since: 2.44

Source: includes/widgets/search-widget/class-search-widget.php:2568

add_search_area_settings_button()

public function add_search_area_settings_button( $area, $type, $values, $is_dynamic, $template_id, $zone ): void

Renders a "Clear all fields" button in the View configuration.

Parameters

NameTypeDefaultDescription
$areaarrayThe area.
$typestringThe type.
$valuesarrayThe values in the area.
$is_dynamicboolWhether the zone is dynamic.
$template_idstringThe template ID.
$zonestringThe zone.

Returns

  • void

Since: 2.44

Source: includes/widgets/search-widget/class-search-widget.php:2588

add_search_area_settings()

public function add_search_area_settings( $settings, $template_id, $field_id ): array

Registers the area settings for the search fields.

Parameters

NameTypeDefaultDescription
$settingsarrayThe area settings.
$template_idstringThe template ID.
$field_idstringThe Field ID.

Returns

  • array

Since: 2.44

Source: includes/widgets/search-widget/class-search-widget.php:2615

render_area_settings()

public function render_area_settings( $is_dynamic, $view, $template_id, $type, $zone ): void

Renders the settings for a search area.

Parameters

NameTypeDefaultDescription
$is_dynamicboolWhether the area is dynamic.
$viewViewThe View.
$template_idstringThe template ID.
$typestringThe object type (widget or field).
$zonestringThe render zone.

Returns

  • void

Since: 2.44

Source: includes/widgets/search-widget/class-search-widget.php:2648