Skip to content

Commit

Permalink
Fix links not using value as well as choice label
Browse files Browse the repository at this point in the history
Fix #511
  • Loading branch information
zackkatz committed Sep 9, 2015
1 parent d5dcf86 commit 1dd573c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions includes/widgets/search-widget/templates/search-field-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
return;
}

/**
* @filter `gravityview/extension/search/links_sep` Change the label for the "Link" search bar input type
* @param string $links_label Default: `Show only:`
*/
$links_label = apply_filters( 'gravityview/extension/search/links_label', __( 'Show only:', 'gravityview' ) );

/**
* @filter `gravityview/extension/search/links_sep` Change what separates search bar "Link" input type links
* @param string $links_sep Default: ` | ` Used to connect multiple links
*/
$links_sep = apply_filters( 'gravityview/extension/search/links_sep', ' | ' );

?>

<div class="gv-search-box">
Expand All @@ -28,13 +38,16 @@
<?php echo esc_html( $links_label ); ?>

<?php
foreach ( $search_field['choices'] as $k => $choice ) :

$search_value = rgget( $search_field['name'] );

foreach ( $search_field['choices'] as $k => $choice ) {

if ( 0 != $k ) {
echo esc_html( $links_sep );
}

$active = ( ! empty( $_GET[ $search_field['name'] ] ) && $_GET[ $search_field['name'] ] === $choice['text'] ) ? ' class="active"' : false;
$active = ( '' !== $search_value && in_array( $search_value, array( $choice['text'], $choice['value'] ) ) ) ? ' class="active"' : false;

if ( $active ) {
$link = remove_query_arg( array( 'pagenum', $search_field['name'] ), $base_url );
Expand All @@ -45,6 +58,6 @@

<a href="<?php echo esc_url_raw( $link ); ?>" <?php echo $active; ?>><?php echo esc_html( $choice['text'] ); ?></a>

<?php endforeach; ?>
<?php } ?>
</p>
</div>

0 comments on commit 1dd573c

Please sign in to comment.