【发布时间】:2021-01-08 18:31:43
【问题描述】:
所以我在整个网站的页脚中有一个范围滑块:
<input id="ex1" type="range" min="0" max="60" step="1" />
<div id='mydiv'>test</div>
在 slideStop 我重定向到我的主页:
$(document).ready(function(){
$('#ex1').on('change', function () {
if (document.location.href.indexOf('category') > -1)
{
window.location.href = 'http://localhost/wordpress/';
}
var id = $(this).val();
$.ajax({
type: "post",
dataType: "json",
url: "/wp-admin/admin-ajax.php",
data: {
action:'get_data',
id: id
},
success:function(data) {
$('#mydiv').html(data);
}
});
});
});
我想将我的范围滑块的值传递到我的 wordpress 首页上的 php 中。这是代码:
<?php
$query = new WP_Query( array( 'tag' => ' ***INSERT RANGE SLIDER VALUE HERE*** ' ) );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();?>
<?php the_content();?>
<?php endwhile; endif;?>
因此,如果范围滑块在 44 处停止,主页将显示所有标记为“44”的帖子。
我以前没有使用过 AJAX,一直在努力理解从哪里开始。
谢谢!
【问题讨论】:
-
问题在于您重定向到您的主页。您必须在主页 url 中传递一个变量以执行操作或更新表格,并在主页上放置一些代码来检查该表格数据。
标签: php html jquery ajax wordpress