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/
|
|
|
|
*
|
|
|
|
* 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:03:16 +01:00
|
|
|
//function POST_look_values_to_submit() {
|
|
|
|
// // look checked values to send
|
|
|
|
// // https://stackoverflow.com/a/10808238
|
|
|
|
// if( isset($_POST['submit-ajut']) ){
|
|
|
|
// echo '<p style="color:#0b0;">$_POST[submit-ajut] set</p>';
|
|
|
|
// if( !empty($_POST[ $fields['name'] ]) ){
|
|
|
|
// echo '<p style="color:#0b0;">$_POST[$fields[name]] not empty</p>';
|
|
|
|
// foreach( $_POST[ $fields['name'] ] as $post_fields_name ) {
|
|
|
|
// $post_fields_name_value_checked[] = $post_fields_name;
|
|
|
|
// };
|
|
|
|
// $all_post_fields_name_values_selection[] = $fields['name'] . '=' . implode(',',$post_fields_name_value_checked);
|
|
|
|
// unset($post_fields_name_values_checked);
|
|
|
|
// } else {
|
|
|
|
// echo '<p style="color:#b00;">$_POST[$fields[name]] empty</p>';
|
|
|
|
// };
|
|
|
|
// //end look for checked values to send
|
|
|
|
// echo '<p style="color:#0b0;">after $_POST:' . $url . '</p>';
|
|
|
|
// };
|
|
|
|
// // end look checked values to send
|
|
|
|
//}
|
|
|
|
|
2023-01-12 08:59:33 +01:00
|
|
|
if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ):
|
|
|
|
function ofisuport_ajuts_filters_form() {
|
2023-01-12 09:03:16 +01:00
|
|
|
|
|
|
|
echo '<div id="archive-filters" class="ofisuport-filters">';
|
2023-01-12 08:59:33 +01:00
|
|
|
// output all possible values of a checkbox
|
2023-01-12 09:03:16 +01:00
|
|
|
|
|
|
|
|
2023-01-12 08:59:33 +01:00
|
|
|
$groupkey = "group_63ab636898703"; // write here the key for the group of fields from acf
|
|
|
|
if( $groupkey ) {
|
2023-01-12 09:03:16 +01:00
|
|
|
|
|
|
|
// start the form
|
|
|
|
echo '<form name="search-ajuts" method="post" action="' . $url . '">';
|
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' ){
|
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
//echo '<span style="color: #00b">' . ($field_key['key']) . '</span><br/>' . '<span style="color: #00b">' . ($field_key['label']) . '</span><br/>' . '<span style="color: #00b">' . ($field_key['name']) . '</span><br/>';
|
|
|
|
|
2023-01-12 08:59:33 +01:00
|
|
|
// https://wordpress.stackexchange.com/a/102915
|
|
|
|
$fields = get_field_object($field_key['key']);
|
|
|
|
if( $fields ) {
|
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
// look checked values to send
|
|
|
|
//POST_look_values_to_submit();
|
|
|
|
// look checked values to send
|
|
|
|
// https://stackoverflow.com/a/10808238
|
|
|
|
if( isset($_POST['submit-ajut']) ){
|
|
|
|
echo '<p style="color:#0b0;">$_POST[submit-ajut] set</p>';
|
|
|
|
if( !empty($_POST[ $fields['name'] ]) ){
|
|
|
|
echo '<p style="color:#0b0;">$_POST[$fields[name]] ' . $fields['name'] . ' not empty</p>';
|
|
|
|
foreach( $_POST[ $fields['name'] ] as $post_fields_name ) {
|
|
|
|
$post_fields_name_value_checked[] = $post_fields_name;
|
|
|
|
};
|
|
|
|
$all_post_fields_name_values_selection[] = $fields['name'] . '=' . implode(',',$post_fields_name_value_checked);
|
|
|
|
unset($post_fields_name_values_checked);
|
|
|
|
} else {
|
|
|
|
echo '<p style="color:#b00;">$_POST[$fields[name]] ' . $fields['name'] . ' empty</p>';
|
|
|
|
};
|
|
|
|
//end look for checked values to send
|
|
|
|
echo '<p style="color:#0b0;">after $_POST:' . implode('?',$all_post_fields_name_values_selection) . '</p>';
|
|
|
|
};
|
|
|
|
// end look checked values to send
|
|
|
|
|
2023-01-12 08:59:33 +01:00
|
|
|
// check for values from meta fields db in url
|
|
|
|
foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ) {
|
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
// check for values in url
|
|
|
|
// 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:03:16 +01:00
|
|
|
|
|
|
|
// construct the checkboxes
|
|
|
|
if( $fieldname == $fields['name']) {
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
echo '<nav id="fund-filter" class="' . $fields['name'] . '">' ;
|
|
|
|
echo '<h5>' . $fields['label'] . '</h5>';
|
|
|
|
echo '<ul>';
|
|
|
|
foreach( $fields['choices'] as $choicevalue => $choicelabel ) {
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
echo '<li>';
|
|
|
|
echo '<label for="' . $choicevalue . '">';
|
|
|
|
echo '<input class="ofisuport-filter filter" type="checkbox" ';
|
|
|
|
echo ' value="' . $choicevalue . '" ';
|
|
|
|
echo ' name="' . $fields['name'] . '[]" ';
|
|
|
|
if( in_array($choicevalue,$filteredvalues['value']) ) {
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
echo ' checked="checked" ';
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
};
|
|
|
|
echo ' />';
|
|
|
|
echo $choicelabel;
|
|
|
|
echo '</label>';
|
|
|
|
echo '</li>';
|
2023-01-12 08:59:33 +01:00
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
};
|
|
|
|
echo '</ul>';
|
|
|
|
echo '</nav>';
|
|
|
|
};
|
|
|
|
// end of construct checkboxes
|
|
|
|
|
|
|
|
};
|
|
|
|
// end check for values from meta fields db in url
|
2023-01-12 08:59:33 +01:00
|
|
|
|
|
|
|
|
2023-01-12 09:03:16 +01:00
|
|
|
};
|
|
|
|
//end if field_key['key']
|
|
|
|
|
|
|
|
};
|
|
|
|
//end if type checkbox
|
|
|
|
|
|
|
|
};
|
|
|
|
//end foreach groupkey field
|
|
|
|
|
|
|
|
$url = home_url('ajuts/?') . implode('&',$all_post_fields_name_values_selection);
|
|
|
|
echo '<p>' . $url . '</p>';
|
|
|
|
//header('Location:'. $url);
|
|
|
|
echo '<button type="submit" name="submit-ajut" class="button-more">enviar</button>';
|
|
|
|
echo '</form>';
|
|
|
|
//close the form and subit
|
|
|
|
//POST_look_values_to_submit();
|
|
|
|
|
|
|
|
};
|
|
|
|
//end if groupkey
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
};
|
|
|
|
//end ofisuport_display_filters()
|
|
|
|
endif;
|
2023-01-12 08:59:33 +01:00
|
|
|
?>
|