2023-01-12 08:59:33 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Function to display the front end checkboxes for the ajut filter
|
|
|
|
*
|
|
|
|
* references:
|
|
|
|
* basic start
|
|
|
|
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
|
|
|
*
|
2023-01-12 09:05:22 +01:00
|
|
|
* wordpress full form example
|
|
|
|
* https://wordpress.stackexchange.com/questions/383599/form-checkbox-value-going-to-dynamic-url
|
|
|
|
*
|
2023-01-12 08:59:33 +01:00
|
|
|
* checkbox adaptation query
|
|
|
|
* https://wordpress.stackexchange.com/a/102915
|
|
|
|
*
|
|
|
|
* form GET and POST
|
|
|
|
* https://www.formget.com/php-checkbox/
|
|
|
|
*
|
|
|
|
* @package Oficina_de_Suport_theme
|
|
|
|
*/
|
2023-01-12 09:05:22 +01:00
|
|
|
?>
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:05:22 +01:00
|
|
|
<?php
|
2023-01-12 08:59:33 +01:00
|
|
|
if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ):
|
|
|
|
function ofisuport_ajuts_filters_form() {
|
2023-01-12 09:05:22 +01:00
|
|
|
?>
|
|
|
|
<div id="archive-filters" class="ofisuport-filters">
|
|
|
|
<?php
|
2023-01-12 08:59:33 +01:00
|
|
|
// output all possible values of a checkbox
|
|
|
|
$groupkey = "group_63ab636898703"; // write here the key for the group of fields from acf
|
|
|
|
if( $groupkey ) {
|
2023-01-12 09:05:22 +01:00
|
|
|
?>
|
|
|
|
<?php // start the form ?>
|
|
|
|
<form id="form-ajuts" name="search-ajuts">
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:05:22 +01:00
|
|
|
<?php
|
2023-01-12 08:59:33 +01:00
|
|
|
$groupkey_fields = acf_get_fields($groupkey);
|
|
|
|
foreach( $groupkey_fields as $field_key ) {
|
|
|
|
|
|
|
|
if( $field_key['type'] == 'checkbox' ){
|
|
|
|
|
|
|
|
// https://wordpress.stackexchange.com/a/102915
|
|
|
|
$fields = get_field_object($field_key['key']);
|
|
|
|
if( $fields ) {
|
|
|
|
|
|
|
|
// check for values from meta fields db in url
|
|
|
|
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ) {
|
|
|
|
|
2023-01-12 09:05:22 +01:00
|
|
|
// check for values in url and get value if available
|
2023-01-12 08:59:33 +01:00
|
|
|
if( isset($_GET[ $fieldname ]) ) {
|
|
|
|
|
|
|
|
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
|
|
|
};
|
|
|
|
//end check for values in url
|
|
|
|
|
2023-01-12 09:05:22 +01:00
|
|
|
// construct the checkboxes
|
|
|
|
if( $fieldname == $fields['name']) {
|
|
|
|
?>
|
|
|
|
|
|
|
|
<section id="fund-filter-<?php echo $fields['name']; ?>" class="<?php echo $fields['name']; ?>">
|
|
|
|
<h5><?php echo $fields['label'];?></h5>
|
|
|
|
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
|
|
|
|
|
|
|
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
|
|
|
<input
|
|
|
|
class="ofisuport-filter"
|
|
|
|
type="checkbox"
|
|
|
|
<?php if( in_array($choicevalue,$filteredvalues['value']) ) { echo 'checked';}; ?>
|
|
|
|
value="<?php echo $choicevalue ?>"
|
|
|
|
name="<?php echo $fields['name'];?>" />
|
|
|
|
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php };//end foreach fields['choices'] ?>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<?php }; //end if fieldname == fields['name'] ?>
|
|
|
|
<?php // end of construct checkboxes ?>
|
|
|
|
|
|
|
|
<?php }; // end check for values from meta fields db in url ?>
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:05:22 +01:00
|
|
|
<?php }; //end if field_key['key'] ?>
|
2023-01-12 09:03:16 +01:00
|
|
|
|
2023-01-12 09:05:22 +01:00
|
|
|
<?php }; //end if type checkbox ?>
|
|
|
|
|
|
|
|
<?php }; //end foreach groupkey field ?>
|
|
|
|
<p><b>Results:</b> <span id="results"></span></p>
|
|
|
|
<button type="button" name="submit-ajut" class="button-more">enviar</button>
|
|
|
|
</form>
|
|
|
|
<?php //close the form and subit ?>
|
|
|
|
|
|
|
|
<?php }; //end if groupkey ?>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function($) {
|
|
|
|
// change
|
2023-01-12 09:07:06 +01:00
|
|
|
//$('#archive-filters').on('change', 'input[type="checkbox"]', function(){
|
|
|
|
$('#archive-filters').on('click', 'button', function(){
|
2023-01-12 09:05:22 +01:00
|
|
|
|
|
|
|
// vars
|
|
|
|
var url = '<?php echo home_url('ajuts/'); ?>';
|
|
|
|
args = {};
|
|
|
|
|
|
|
|
// loop over filters
|
|
|
|
$('#archive-filters .filter').each(function(){
|
|
|
|
urldos = url;
|
|
|
|
// vars
|
|
|
|
var filteredajuts = $(this).data('filter'),
|
|
|
|
vals = [],
|
2023-01-12 09:07:06 +01:00
|
|
|
allvalueschecked = [];
|
2023-01-12 09:05:22 +01:00
|
|
|
// find checked inputs
|
|
|
|
$(this).find('input:checked').each(function(){
|
|
|
|
vals.push( $(this).val() );
|
|
|
|
var thisvaluechecked = $(this).val();
|
|
|
|
urldos += filteredajuts;
|
|
|
|
});
|
|
|
|
|
|
|
|
// append to args
|
|
|
|
args[ filteredajuts ] = vals.join(',');
|
2023-01-12 09:07:06 +01:00
|
|
|
alert( filteredajuts +'=' +args[ filteredajuts ]);
|
2023-01-12 09:05:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// update url
|
|
|
|
url += '?';
|
|
|
|
|
|
|
|
// loop over args
|
|
|
|
$.each(args, function( name, value ){
|
|
|
|
url += name + '=' + value + '&';
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove last &
|
|
|
|
url = url.slice(0, -1);
|
|
|
|
|
|
|
|
// reload page
|
2023-01-12 09:07:06 +01:00
|
|
|
//$('#archive-filters button').on('click', function () {
|
2023-01-12 09:05:22 +01:00
|
|
|
alert( "estoy en: " +url );
|
|
|
|
//window.location.replace( url );
|
2023-01-12 09:07:06 +01:00
|
|
|
//});
|
2023-01-12 09:05:22 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}; //end ofisuport_display_filters()
|
|
|
|
endif; // end if ! functionexists
|
2023-01-12 08:59:33 +01:00
|
|
|
?>
|