【发布时间】:2014-08-10 20:02:56
【问题描述】:
我正在运行 AJAX 调用,它将选择选项值(从状态下拉列表中)传递到 Wordpress 查询中。
这是我的 AJAX 调用:
$.ajax({
url:"<?php bloginfo('template_directory'); ?>/inc/businesses.php",
type: 'POST',
data: {postID: '<?php the_ID(); ?>', postState: $("#state").val()},
success: function(resp) {
$('#results').html(resp);
}
});
这是来自businesss.php的部分代码:
<?php
require('../../../../wp-load.php');
$postState = $_POST['postState'];
$userState = geoCheckIP($ip);
?>
<?php
$args = array(
'post_type' => 'businesses',
'orderby' => 'date',
'order' => "ASC",
'meta_query' => array(
array(
'key' => 'state',
'value' => $userState,
'compare' => '=',
'type' => 'CHAR'
)
)
);
// Query
$the_query = new WP_Query( $args );
?>
基本上我想在页面加载时将$userState 传递到查询参数中,然后在更改选择下拉菜单时将$userState 与$postState 交换。
【问题讨论】:
标签: javascript php jquery ajax wordpress