Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpeb-filter-with-default-value.php: Added snippet to load Entries Block with a provided default value on a filter. #807

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gp-entry-blocks/gpeb-filter-with-default-value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Gravity Perks // Entry Blocks // Apply Default Value to Filter on Page Load
* https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
*
* Filter entries on Page Load with a provided default value
*/
use function GP_Entry_Blocks\get_current_url;
add_action( 'gpeb_before_render_block', function( $block ) {
if ( ! isset( $_GET['filters'] ) ) {
wp_safe_redirect( add_query_arg( array(
// REPLACE "3" with the Field ID of your Field.
// REPLACE "date( 'Y-m-d' )" with your default value.
// This example target Date Field ID 3 to work with the current date as default value.
'filters' => array( 3 => date( 'Y-m-d' ) ),

Check failure on line 15 in gp-entry-blocks/gpeb-filter-with-default-value.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.
'filters_form_id' => rgar( $block->context, 'gp-entry-blocks/formId' ),
), get_current_url() ) );
}
}, 10 );
Loading