I’m trying to pass multiple values trough checkboxes using WordPress Custom Taxonomies. So far this is what I got.

HTML

<?php
    $taxonomy = 'locatie';
    $queried_term = get_query_var($taxonomy);
    $terms = get_terms($taxonomy, 'slug='.$queried_term);
            if ($terms) {
              foreach($terms as $term) {
              $name = $term->name;
              echo "
                <form id='location'>
                 <input class='checkIt' type='checkbox' value='".$name."' name='location' id='".$name."_id'>&nbsp;&nbsp;".$name."
                </form>";                            
              }
        }
?>

jQuery
I have the else statement to have the page return to the default one when a checkbox is unchecked.

$('.checkIt').click(function() {
    var value = $(this).val();
    if($(".checkIt").is(':checked'))
    $.ajax({
        type: "POST",
        url: '../wp-content/themes/mysite/includes/search-team-wp.php',
        data: { value:value },
        success: function(data) {
            $('#search_results_team').hide().fadeIn(1100);
             $("#search_results_team").html(data);
             console.log(value);
        }
    });
    else{
        var value = $('#str').val();
        $.ajax({
        type: "POST",
        url: '../wp-content/themes/mysite/includes/search-team.php',
        data: { value:value },
        success: function(data) {
            $('#search_results_team').hide().fadeIn(1100);
             $("#search_results_team").html(data);
             console.log(value);
        }
    });}
});

AJAX (search-team-wp.php)

<?php session_start(); ?>
<?php
/*
Template Name: Search Page
*/
?>
<?php 
$value = $_POST['value'];
$path = $_SERVER['DOCUMENT_ROOT'];

    include_once $path . '/wp-config.php';
    include_once $path . '/wp-load.php';
    include_once $path . '/wp-includes/wp-db.php';
    include_once $path . '/wp-includes/pluggable.php';

?>
<div class="container">
  <div class="row">
<?php
$s=$_POST['value'];
$locat = array($s,);
$args = array(
        'post_type' => 'team',
        'orderby' => 'title',
        'order' => 'ASC',
        'posts_per_page' => -1,
        'locatie' =>$locat

            );

$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
           $the_query->the_post();
           $value = get_the_id();
           $mail = get_field('e-mail_adres', $value);
           $afd = get_field('functie', $value);
           $intrn = get_field('intern_telefoonnummer', $value);
           $mob = get_field('mobiel', $value);
           $locatie = get_field('locatie', $value);
?>

  <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
    <div class="block">
      <div style="min-height:150px;"> 
              <div class="col-xs-12 row">

                <h3 class="text-left"><?php the_title(); ?></h3>  
             </div>
            <div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
              <div class="thumbnail-image">
                <?php echo get_the_post_thumbnail(); ?>
              </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-9 col-lg-9">
              <div class="row">
                <table class="zoek-col">
                  <?php if( get_field('intern_telefoonnummer') ): ?>
                    <tr>
                  <td class="td-top">Tel. Intern:</td>
                      <td><?php the_field('intern_telefoonnummer'); ?></td>
                    </tr>
              <?php endif; ?>
                  <?php if( get_field('intern_utr') ): ?>
                    <tr>
                  <td class="td-top">Tel. Intern (extra):</td>
                      <td><?php the_field('intern_utr'); ?></td>
                    </tr>
              <?php endif; ?>
                  <tr>
                    <td class="td-top">E-mail adres:</td>
                    <td><a href="mailto:<?php echo $mail; ?>"><?php echo $mail; ?></a></td>
                  </tr>
                  <?php if( get_field('mobiel_werk') ): ?>
                    <tr>
                  <td class="td-top">Mobiel werk:</td>
                      <td><?php the_field('mobiel_werk'); ?></td>
                    </tr>
              <?php endif; ?>
                  <tr>
                    <td class="td-top">Mobiel privé:</td>
                    <td><?php echo $mob; ?></td>
                  </tr>
                  <?php if( get_field('locatie') ): ?>
                    <tr>
                  <td class="td-top">Locatie:</td>
                      <td><?php the_field('locatie'); ?></td>
                    </tr>
              <?php endif; ?>
                </table>
              </div>
            </div>          
          </div> 
    </div>
  </div>       

<?php }} else { ?>
  <h3>Geen collega's gevonden</h3>
      <p style="font-size:1.3rem;">Probeer het opnieuw</p>
<?php } ?>
  </div>
</div>

I started using an Array to fill the multiple values, but that doesn’t give me what I want. The best why I can describe this is like an SQL query. Say Location 1 is Amsterdam and Location 2 is Rotterdam. I would like that have the checkboxes respond to show the team members from Amsterdam AND Rotterdam. I really don’t know what to do here…

Read more here: Pass mulitple values using checkboxes wordpress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: