GravityView
2.17
The best, easiest way to display Gravity Forms entries on your website.
includes
widgets
search-widget
templates
search-field-link.php
Go to the documentation of this file.
1
<?php
2
/**
3
* Display the search LINK input field
4
*
5
* @file class-search-widget.php See for usage
6
*/
7
8
$gravityview_view
=
GravityView_View::getInstance
();
9
$view_id
=
$gravityview_view
->getViewId();
10
$search_field
=
$gravityview_view
->search_field;
11
12
// base url to calculate the final full link
13
$base_url
=
GravityView_Widget_Search::get_search_form_action
();
14
15
// Make sure that there are choices to display
16
if
( empty(
$search_field
[
'choices'
] ) ) {
17
gravityview
()->log->debug(
'search-field-link.php - No choices for field'
);
18
return
;
19
}
20
21
$links_label
= empty(
$search_field
[
'label'
] ) ? __(
'Show only:'
,
'gk-gravityview'
) :
$search_field
[
'label'
];
22
23
/**
24
* @filter `gravityview/extension/search/links_label` Change the label for the "Link" search bar input type
25
* @since 1.17 Use search field label as default value, if set. Before that, it was hard-coded to "Show only:"
26
* @param string $links_label Default: `Show only:` if search field label is not set. Otherwise, search field label.
27
*/
28
$links_label
= apply_filters(
'gravityview/extension/search/links_label'
,
$links_label
);
29
30
/**
31
* @filter `gravityview/extension/search/links_sep` Change what separates search bar "Link" input type links
32
* @param string $links_sep Default: ` | ` Used to connect multiple links
33
*/
34
$links_sep
= apply_filters(
'gravityview/extension/search/links_sep'
,
' | '
);
35
36
?>
37
38
<div
class
=
"gv-search-box gv-search-field-link gv-search-box-links"
>
39
<p>
40
<?php echo esc_html(
$links_label
); ?>
41
42
<?php
43
44
$search_value
=
\GV\Utils::_GET
(
$search_field
[
'name'
] );
45
46
foreach
(
$search_field
[
'choices'
] as $k => $choice ) {
47
48
if
( 0 != $k ) {
49
echo esc_html(
$links_sep
);
50
}
51
52
$active = (
''
!==
$search_value
&& in_array(
$search_value
, array( $choice[
'text'
], $choice[
'value'
] ) ) ) ?
' class="active"'
:
false
;
53
54
if
( $active ) {
55
$link
= remove_query_arg( array(
'pagenum'
,
$search_field
[
'name'
] ),
$base_url
);
56
}
else
{
57
$link
= add_query_arg( array(
$search_field
[
'name'
] => urlencode( $choice[
'value'
] ) ), remove_query_arg( array(
'pagenum'
),
$base_url
) );
58
}
59
?>
60
61
<a href=
"<?php echo esc_url_raw( $link ); ?>"
<?php echo $active; ?>><?php echo esc_html( $choice[
'text'
] ); ?></a>
62
63
<?php } ?>
64
</p>
65
</div>
$view_id
$view_id
Definition:
search-field-link.php:9
$base_url
$base_url
Definition:
search-field-link.php:13
GV\Utils\_GET
static _GET( $name, $default=null)
Grab a value from the _GET superglobal or default.
Definition:
class-gv-utils.php:21
GravityView_View\getInstance
static getInstance( $passed_post=NULL)
Definition:
class-template.php:195
GravityView_Widget_Search\get_search_form_action
static get_search_form_action()
Calculate the search form action.
Definition:
class-search-widget.php:1561
$link
if( $add_query_args) $link
Definition:
field-entry_link-html.php:52
$search_field
$search_field
Definition:
search-field-link.php:10
$gravityview_view
$gravityview_view
Definition:
search-field-link.php:8
$links_label
if(empty( $search_field['choices'])) $links_label
Definition:
search-field-link.php:21
$links_sep
$links_sep
Definition:
search-field-link.php:34
$search_value
$search_value
Definition:
search-field-link.php:44
gravityview
gravityview()
The main GravityView wrapper function.
Definition:
future/gravityview.php:26