使用复选框wordpress传递多个值

时间:2017-04-05 10:35:09

标签: php jquery html wordpress checkbox

我正在尝试使用Wordpress自定义分类法通过复选框传递多个值。到目前为止,这就是我所得到的。

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 当复选框为else时,我有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>

我开始使用Array来填充多个值,但这并不能满足我的需求。我能描述的最好的原因就像SQL查询一样。 Say位置1是阿姆斯特丹,位置2是鹿特丹。我希望有复选框响应显示来自Amsterdam AND Rotterdam的团队成员。我真的不知道该怎么做......

0 个答案:

没有答案