Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saifsultanc/94c4e15c22106039a2abaf75efeb5a49 to your computer and use it in GitHub Desktop.
Save saifsultanc/94c4e15c22106039a2abaf75efeb5a49 to your computer and use it in GitHub Desktop.
gpeb-navigation-with-filtered-choices.php
<?php
// helper method
function get_array_subset( $array, $offset, $limit ) {
if ( $offset > count( $array ) - 1) {
return [];
}
$start = $offset;
$length = min( $limit, count( $array ) - $offset );
return array_slice( $array, $start, $length );
}
add_filter( 'gpeb_queryer_entries', function( $entries, $gf_queryer ) {
$form_id = $gf_queryer->form_id;
$filtered_entries = array_filter( GFAPI::get_entries( $form_id ), function( $entry ) {
if ( $entry[1] != 'First Choice' ) {
return false;
}
return true;
});
$offset = rgget( 'offset' );
$limit = $gf_queryer->block_context['gp-entry-blocks/limit'];
$gf_queryer->entries = get_array_subset( $filtered_entries, $offset, $limit );
$gf_queryer->total_count = count( $filtered_entries );
return $gf_queryer->entries;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment