lundi 15 juin 2020

How to get both 'value' and 'checked' from a checkbox input - wordpress php and acf

I have an ajax posts filter (and its working), that displays the results from functions.php file. I'm trying to compare checked checkboxes in a form, to checked checkboxes in the post edit page (both are from same acf plugin field). For checking if a ceckbox is checked, i need its value to be on/off. so I cant compare by value. So it's either I get 'if checked', either I get the value I want. What am I missing?

html form input code:

<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="filter">
    <label for="chk"> 25<input type="checkbox" name="chk"> </label>
    <button>Apply filter</button>
        <input type="hidden" name="action" value="myfilter">
</form>
<div id="response"></div>

the $_POST part in the function ('weather' is the custom field):

if( isset( $_POST['chk'] ) && $_POST['chk'] == 'on' )
    $args['meta_query'][] = array(
    'key' => 'weather',
    'value' => $_POST['chk'],
    'compare' => 'LIKE'
    );



Aucun commentaire:

Enregistrer un commentaire