Php 使用复选框wordpress传递多个值
我正在尝试使用Wordpress自定义分类法通过复选框传递多个值。到目前为止,这就是我得到的 HTMLPhp 使用复选框wordpress传递多个值,php,jquery,html,wordpress,checkbox,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
<?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'> ".$name."
</form>";
}
}
?>
AJAX(搜索团队wp.php)
实习电话:
实习电话(额外):
电子邮件地址:
莫比尔·沃克:
Mobiel privé:
地点:
吉恩·科莱加的格沃登
Probeer-het-opnieuw
我开始使用
数组
填充多个值,但这并不能满足我的需要。我所能描述的最好的解释就是SQL查询。假设位置1是阿姆斯特丹,位置2是鹿特丹。我想让复选框显示来自阿姆斯特丹和鹿特丹的团队成员。我不知道该怎么做。编写自己的页面作为ajax调用是不好的做法。Wordpress有一个内置的方法来生成您自己的ajax请求。看,我知道,但这个页面仍处于开发阶段,我只是想让它像这样工作。。。之后,我将以正式的方式进行操作……我相信name需要name=“location[]”来表示它是一个数组。这样,它可以包含多个复选框数据。
$('.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);
}
});}
});
<?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>